GroupLayout error with java swing

I get a long list of errors. Can anyone suggest me where I'm wrong, GroupLayout .

 layout.setHorizontalGroup( layout.createSequentialGroup() .addComponent(new JLabel("Enter Book Name")) .addComponent(new JTextField("TextField", 20)) ); 

Mistake:

     Exception in thread "main" java.lang.IllegalStateException:
         javax.swing.JTextField [, 0,0,0x0, invalid, layout = javax.swing.
             plaf.basic.BasicTextUI $ UpdateHandler, alignmentX = 0.0,
             alignmentY = 0.0, border = javax.swing.plaf.BorderUIResource $
             CompoundBorderUIResource @ 3d0bbf9e, flags = 296, maximumSize =,
             minimumSize =, preferredSize =, caretColor = sun.swing.
             PrintColorUIResource [r = 51, g = 51, b = 51], disabledTextColor = javax
             .swing.plaf.ColorUIResource [r = 184, g = 207, b = 229], editable = true
             , margin = javax.swing.plaf.InsetsUIResource [top = 0, left = 0,
             bottom = 0, right = 0], selectedTextColor = sun.swing.
             PrintColorUIResource [r = 51, g = 51, b = 51], selectionColor = javax.
             swing.plaf.ColorUIResource [r = 184, g = 207, b = 229], columns = 20,
             columnWidth = 0, command =, horizontalAlignment = LEADING]
             is not attached to a vertical group
             at javax.swing.GroupLayout.checkComponents (Unknown Source)
             at javax.swing.GroupLayout.prepare (Unknown Source)
+8
java layout swing grouplayout
source share
1 answer

When you use GroupLayout, you must specify the horizontal and vertical layout. Each component must be specified exactly once in each group. This does not lead to this error.

Also, make sure you cross each element correctly. If you are making a grid, make sure that both directions are sequences of parallels or vice versa. If you are doing one row of buttons or something like that, make sure they are parallel to each other in the same direction and sequentially.

+15
source share

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


All Articles