Android's LinearLayout for Swing

旧时模样 提交于 2019-12-12 11:14:49

问题


Is there a LayoutManager for Swing that acts as LinearLayout in Android? I like an idea of components weights very much.


回答1:


If you need individual weights use GridBagLayout. Or you can try BoxLayout.




回答2:


You can use the FlowLayout, GridLayout or BorderLayout. In my experience in building GUI in java, I mostly use combinations of BorderLayouts (most of the time) and GridLayouts.

Layout Basics

If you want it to look like

the code is:

public void initComponents() {

    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jButton4 = new javax.swing.JButton();

    setLayout(new java.awt.GridLayout(0, 1));

    jButton1.setText("jButton1");
    add(jButton1);

    jButton2.setText("jButton2");
    add(jButton2);

    jButton3.setText("jButton3");
    add(jButton3);

    jButton4.setText("jButton4");
    add(jButton4);
}


来源:https://stackoverflow.com/questions/9409498/androids-linearlayout-for-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!