How can I make a gui layout in java which is column based? by that i mean:
JLabel
JTextField
JLabel
JTextField
JLabel
JTextField
I want them all stacked on to of each other, rather than side by side. In the past I’ve used FlowLayout which isn’t suitable, and gridLayout which makes each component much larger than I require. Any ideas?
Look at BoxLayout, but more important, go through the layout manager tutorial to get an overview of all the user-friendly layout managers.
Edit 1:
Also, GridLayout sometimes works well in this situation, but you may want to place your JTextFields inside of JPanels and add the JPanels to the grid, so that the JTextFields aren’t huge looking.
Edit 2:
If you have a bunch of JTextFields with associated JLabels, I’ve had success and fun working from an array of String that represents the JLabel texts, and then placing the JTextFields into a
Map<String, JTextField>so that I can easily get a reference to the JTextField based on it’s related String. Example to follow…Edit 3
as promised, the example: