Android LinearLayout for Swing

Is there a LayoutManager for Swing that acts like LinearLayout in Android? I really like the idea of ​​component weights.

+4
source share
2 answers

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

+2
source

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

Layout Basics

If you want it to look like

enter image description here

the code:

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); } 
+5
source

Source: https://habr.com/ru/post/1397979/


All Articles