0

有没有办法创建 Netbeans Matisse 垂直流布局,如:

垂直流布局

但是 Netbeans Matisse Flow Layout 像这样创建: 水平流布局

4

1 回答 1

1

FlowLayout将自动“包装”宽度超出它们所在容器边界的组件。因此,要完成我认为您要完成的工作,您需要做的就是FlowLayout像您所做的那样设置并调整大小JTextFields 到适当的宽度。

注意:“我的想法”是对您的问题并不能真正帮助我们确切了解您要完成的工作这一事实的尖锐批评。

五秒JTextField

在此处输入图像描述

请注意,如果您调整一个大小,它将“包裹”其他的:

在此处输入图像描述

您可以同时选择多个组件并调整其大小:

在此处输入图像描述

我将宽度更改为 250: 在此处输入图像描述

中提琴:

在此处输入图像描述

代码:

public class NewJFrame2 extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame2
     */
    public NewJFrame2() {
        initComponents();
        setSize(287,200);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.FlowLayout());

        jTextField1.setText("jTextField1");
        jTextField1.setPreferredSize(new java.awt.Dimension(250, 20));
        getContentPane().add(jTextField1);

        jTextField2.setText("jTextField2");
        jTextField2.setPreferredSize(new java.awt.Dimension(250, 20));
        getContentPane().add(jTextField2);

        jTextField3.setText("jTextField3");
        jTextField3.setPreferredSize(new java.awt.Dimension(250, 20));
        getContentPane().add(jTextField3);

        jTextField4.setText("jTextField4");
        jTextField4.setPreferredSize(new java.awt.Dimension(250, 20));
        getContentPane().add(jTextField4);

        jTextField5.setText("jTextField5");
        jTextField5.setPreferredSize(new java.awt.Dimension(250, 20));
        getContentPane().add(jTextField5);

        pack();
    }// </editor-fold>                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration                   
}
于 2014-02-17T13:15:57.947 回答