• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

JList with DefaultListModel is too wide when adding the viewPortView.

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, the first list is what my frame looks like when creating with all the layout managers.  It is a Box Layout y axis, with a nested Box Layout x Axis, with 2 nested GridBag Layouts at the ends and a nested Grid Layout in the center.

The frame packs just fine, until added the JLists to the scroll panes.  As soon as I add them, it looks like the 2nd picture.






The copy and pasted code will execute in Eclipse and possibly other IDEs.  

If you take out the setViewPortView, it will look exactly like picture 1.  
Cabin-JLists.png
[Thumbnail for Cabin-JLists.png]
Cabin-JLists-Screwed-Up.png
[Thumbnail for Cabin-JLists-Screwed-Up.png]
 
Nathan Milota
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far, what I did that seems to work, is I set the preferred size of the scrollPane to 0,0.  That way, it makes it as small as it can fit inside the scrollPane, which the ipadx and ipady have already been set.  I'm hoping this won't mess with the rest of the frame though.
 
Rancher
Posts: 507
15
Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this with a JFrame as the main window and the components added to it using a GridBagLayout. This creates the GUI (see attached image) without any issues. Some details:

The grid bag layout has 8 rows and 3 columns. The following details each row:

1: Select cabin JLabel. This is in the 2nd column.
2: Cabins JComboBox. This is spread over the three columns.
3: Select JButton is in the 2nd column.
4: Councelors JLabel in 1st column and Assigned councelors JLabel in 3rd column.
5: Councelors JList in the 1st column. Assigned councellors JList in 3rd column. The button panel in the 2nd column; the two JButtons are placed in a JPanel with a BoxLayout in Y-AXIS. The buttons are seperated (vertically) by a JSeparator.
6: Campers JLabel in 1st column and Assigned campers JLabel in 3rd column.
7: Campers JList in the 1st column. Assigned campers JList in 3rd column. The button panel in the 2nd column; the two JButtons are placed in a JPanel with a BoxLayout in Y-AXIS. The buttons are seperated (vertically) by a JSeparator.
8: Close JButton is in the 2nd column.

In addition I had used some padding/margins/sizing for various components:

- JFrame has an EmptyBorder of 5.
- The councellors and campers JLists have a preferred size of 210 x 220 and 210 x 180 respectively.
EDIT: The councellors and campers JLists are placed in JScrollPane's with a preferred size of 210 x 220 and 210 x 180 respectively.

Within the grid bag layout:
- The councelors JLabels has a external padding (GridBagConstraints.insets) of 10,5,5,5.
- The campers JLabels has a padding of 15,5,5,5.
- The close JButton has a padding of 15,5,5,5.
- All others have a padding of 5,5,5,5.
- All the JLists have the GridBagConstraints.weightx and weighty set to 1.

Finally, note the JFrame (the main window's) size is not set; it sized itself (thats the image of the window). I am using Java SE 8 and not using an IDE. I hope this is useful in someway to fix the issues faced in creating the GUI.


                                 

 
Prasad Saya
Rancher
Posts: 507
15
Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried this with a JFrame as the main window and the components added to it using a GridBagLayout. This creates the GUI (see attached image) without any issues. Some details:
The grid bag layout has 8 rows and 3 columns. The following details each row: ...



A correction in the above message:

Where I had mentioned JList within the grid bag layout it should be the respective JScrollPane within which that specific JList is placed.


 
Nathan Milota
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My final result looks just like this (only the counselor lists are smaller, due to less counselors than campers), but I just did it a bit differently, and maybe a little more tedious.  

My The main panel that covered the screen was a JPanel vertical box layout.  Inside that layout I had a horizontal box layout with two grid bag layouts on the left and right with the scroll panes, and a middle grid layout with the buttons.    I think I would have had the same problem doing it with all grid bag layout though, because the scroll panes were getting huge when putting the lists in them, and the lists were in a nested grid bag layout.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!