首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >马蒂斯垂直流布局

马蒂斯垂直流布局
EN

Stack Overflow用户
提问于 2014-02-17 12:28:35
回答 1查看 366关注 0票数 0

有没有一种方法可以像这样创建Netbeans Matisse垂直流布局:

但Netbeans Matisse Layout是这样创建的:

EN

回答 1

Stack Overflow用户

发布于 2014-02-17 21:15:58

FlowLayout将自动“包装”宽度超出容器边界的组件。因此,要完成我认为您正在尝试完成的任务,您所需要做的就是像您所做的那样设置FlowLayout,并将JTextField调整为适当的宽度。

注意:"what I think“是对这样一个事实的尖锐批评,即您的问题并不能真正帮助我们了解您想要实现的目标。

五个JTextField

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

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

我将宽度更改为250:

维奥拉:

代码:

代码语言:javascript
复制
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                   
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21820769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档