What do you people suggest I use for a layout when I have a bunch of JLabels next to a bunch of corresponding JTextFields? I am currently using BorderLayout, but they line up with the JLabel, not eachother. I also tried using GridLayout(5,2) for example, but my window is large and the JTextFields are spaced too far from the JLabels. I also took a quick glance at GridBagLayout, but that seemed quite a bit more complicated than this should be (was hoping it was just a simple setx, sety for placement). What do you all think I should use for a layout to do this the simplest way? Also, is there a way to actually size a JTextField without an ActionListener? For example, having a "new JTextField(10)" only be about 1.5 inches wide on the screen (just an example, size may vary).
i think u could use panel within panels with different layout managers mainly border and flow layout i have just tried it,works but quite tedious the best to use is the gridbaglayout its not that difficult or if u think it is then u could use the borderlayout east or west(depeding on which side to place it) and center i.e a label and a text field in one panel east or west(depending on which side ) and center then add this panel to another panel with flow layout i think u should do this for every label and textfield they should align when u finish u now add all the panels in one panel again using gridlayout well we sort of had to do it this way in class for practice it worked its quite tedious and needs alot of thinking but gridbag is the best and most simple one its ur choice ----------------- khella smith
Joined: Dec 19, 2001
Thanks for trying to help. I did some more searches in the AWT / Swing conference here as well as on Sun's site. Unfortunately, GridBagLayout seems way more complicated than anything I needed to deal with. So, fortunate for me, I thought up a different way to do it. Here's how I did it... The height of my window is approximately 25 lines high (GirdLayout size mind you). So I made my big this.setLayout(new BorderLayout()). I created a new JPanel.setLayout(new GridLayout(25,1)) to hold all of my JLabels. Then I added that panel to the contentPane,BorderLayout.WEST. THEN I created another new JPanel.setLayout(new GridLayout(25,1)) to hold all of my JTextFields... then added that to my contentPane,BorderLayout.CENTER so it'd take as much space as it could and butt up against my JLabels and line up with each other! Works great! Thanks!
Joined: May 17, 2001
Quick example with GridBagLayout. You could play with the settings just a little to get the effect you want. Maybe have the GridBagLayout components in their own panel.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com