Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java设计用户界面_Java_User Interface_Jframe - Fatal编程技术网

Java设计用户界面

Java设计用户界面,java,user-interface,jframe,Java,User Interface,Jframe,我正在用java(以编程方式)制作一个特定的UI,但我无法实现我的目标UI。我需要帮助实现我的目标。我甚至尝试了SWT Designer,但仍然没有成功。提前谢谢 我的代码: public class Main{ /** * @param args */ static JTextArea lblOne = new JTextArea ("Enter Nb Of Rows"); static JButton btn1 = new JButton("

我正在用java(以编程方式)制作一个特定的UI,但我无法实现我的目标UI。我需要帮助实现我的目标。我甚至尝试了SWT Designer,但仍然没有成功。提前谢谢

我的代码:

public class Main{

    /**
     * @param args
     */

    static JTextArea  lblOne = new JTextArea ("Enter Nb Of Rows");
    static JButton btn1 = new JButton("Generate Table");
    final static TextField tf1 = new TextField();

    static JFrame AFrame;

    public static void main(String[] args) {
        // TODO Auto-generated method stub

           AFrame = new JFrame("Pascal's Table Generator");

          AFrame.setLayout(new BorderLayout());

          // Add a window listner for close button
          AFrame.addWindowListener(new WindowAdapter() {

                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            });


          tf1.setText("");



          //AFrame.add(lblOne);
          //lblOne.setText("                        \n                     ");

            //JTextArea textArea = new JTextArea(5, 5);
            JScrollPane scrollableTextArea = new JScrollPane(lblOne);

            scrollableTextArea.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            scrollableTextArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);





            AFrame.getContentPane().add(scrollableTextArea);

         // AFrame.add(new JScrollPane(lblOne));
          AFrame.add(btn1);
          AFrame.add(tf1);
          AFrame.setSize(800, 800);


          btn1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                lblOne.setText("");

                genPyrN(Integer.parseInt(tf1.getText().toString()));
            }
        });


          //set the layout of the frame to FlowLayout
          //and align the components to the center
          AFrame.setLayout(new FlowLayout(FlowLayout.CENTER));
         AFrame.setVisible(true);
当前用户界面:

目标用户界面:

首先,您应该阅读更多关于Java中LayoutManager的信息,我喜欢这一个:

在这种具体情况下,边界布局是一个好主意。框架可以有边框布局,JScrollPane可以进入中间部分,按钮可以向北


但是在代码中设置BorderLayout之后,这就没有意义了:
AFrame.setLayout(newflowLayout(FlowLayout.CENTER))。我建议创建一个JPanel,在其中添加按钮,然后将此面板放在BorderLayouts的北部。

那么问题出在哪里?在添加组件后,您可能需要“重新绘制”。如果您对ui设计不熟悉,请使用netbeans之类的工具,并在netbeans中使用GUI生成器分析生成的代码。