我从MIG Layout的演示应用程序中查找了一些示例GUI,可从其站点下载Swing。
www.migcalendar.com/miglayout/swingdemoapp.jnlp

我查看了样本并喜欢它们的格式。它们还显示了源代码。他们显示源代码给出了以下输出



我用了,这就是我要的方式



我正在使用的代码是

    frame = new JFrame();
    frame.setBounds(200, 100, 733, 533);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new MigLayout("ins 20","[para]0[][1001p,fill][601p][951p,fill]"));

    JLabel sepLabel = new JLabel("ISD Authorization Parameters   ");
    frame.getContentPane().add(sepLabel);
    addSeparator(frame);

    JLabel label1 =  new JLabel("ISD Server Hostname");
    frame.getContentPane().add(label1,"skip");
    final JTextField field1 = new JTextField(getSystemName());
    frame.getContentPane().add(field1,"growx,span");



    JLabel label2 =  new JLabel("ISD Version");
    frame.getContentPane().add(label2,"skip");
    final JTextField field2 = new JTextField(getVersion());
    frame.getContentPane().add(field2,"growx,wrap");

    JLabel label3 =  new JLabel("ISD Port");
    frame.getContentPane().add(label3,"skip");
    final JTextField field3 = new JTextField(getSystemPort());
    frame.getContentPane().add(field3,"growx,wrap,span");

    JLabel label4 =  new JLabel("ISD UserID");
    frame.getContentPane().add(label4,"skip");
    final JTextField field4 = new JTextField(getUser());
    frame.getContentPane().add(field4,"growx,span");

    JLabel label5 =  new JLabel("ISD Password");
    frame.getContentPane().add(label5,"skip");
    final JPasswordField field5 = new JPasswordField(getSystemPassword());
    frame.getContentPane().add(field5,"growx,wrap,span,wrap para");

    JLabel sepLabel1 = new JLabel("Key Store Authorization   ");
    frame.getContentPane().add(sepLabel1);
    addSeparator(frame);

    JLabel label6 =  new JLabel("KeyStore Password");
    frame.getContentPane().add(label6,"skip");
    final JPasswordField field6 = new JPasswordField(getKeystorePassword());
    frame.getContentPane().add(field6,"growx,span,wrap para");

    JLabel sepLabel2 = new JLabel("Key Store Authorization   ");
    frame.getContentPane().add(sepLabel2);
    addSeparator(frame);

    JLabel label7 =  new JLabel("PowerVC IP Address");
    frame.getContentPane().add(label7,"skip");
    final JTextField field7 = new JTextField(getHost());
    frame.getContentPane().add(field7,"growx,wrap,span");

    JLabel label8 =  new JLabel("PowerVC User ID");
    frame.getContentPane().add(label8,"skip");
    final JTextField field8 = new JTextField(getUser());
    frame.getContentPane().add(field8,"growx,span");


    System.out.println("The value of getPassword is "+getPassword());
    JLabel label9 =  new JLabel("PowerVC password");
    frame.getContentPane().add(label9,"skip");
    final JPasswordField field9 = new JPasswordField(getPassword());
    frame.getContentPane().add(field9,"growx,span,wrap para");

    JButton cancelButton = new JButton("Cancel");
    frame.getContentPane().add(cancelButton,"span,split,align right");

    JButton updateButton = new JButton("Update");
    frame.getContentPane().add(updateButton,"");


    JButton updateAndExitButton = new JButton("Update and Exit");
    frame.getContentPane().add(updateAndExitButton,"");


    frame.setVisible(true);

    private void addSeparator(JFrame frame2) {


        JSeparator sep1 = new JSeparator(SwingConstants.HORIZONTAL);
        sep1.setBackground(Color.CYAN);
        frame2.getContentPane().add(sep1,"growx,wrap,span");


    }

}


在我的GUI外观中,比较我的GUI中的字体外观。接缝人如何在制造商,制造商和公司对齐之后开始工作,更具体地说,我想要这种外观,但我做的东西看起来并不好

最佳答案

诀窍是在标签/分隔符对中同时使用跨度和分割(如在演示代码中可以看到的那样:-)

panel.add(label, "gapbottom 1, span, split 2, aligny center");
panel.add(new JSeparator(), "gapleft rel, growx");

09-10 05:49
查看更多