2

I would like to add components (JButton and JSpinner) to a JPanel which was created using Netbeans GUI builder. This panel uses GroupLayout, and I can't seem to use add() to add a component. Is there any way to either add something to a panel which has a GroupLayout, or change this panel to a FlowLayout?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

1

It's definitely not an easy thing to do. It depends on where you want to add those components. I usually reserve an empty placeholder JPanel with GUI builder, and then add components to that panel, using whatever layout I want. However, this only works when you want to add components in one place. If they are scattered around the GUI, it may be not that easy.

Another options is to migrate to manual GUI creation, possibly using Netbeans-generated code as a starting point. But depending on how complex your GUI is, it may be a tedious work.

Sergei Tachenov
  • 24,345
  • 8
  • 57
  • 73
  • Thanks for your answer, but I found out there is an option to set the layout of an auto-generated JPanel. So I just used that and it seems to work now. – javaNoobsForever Apr 21 '16 at 09:06
0

There is an option if you right-click the JPanel to change it to a FlowLayout (Set Layout). This fixed all the problems I was having.