How do I stop JLists from resizing when long String(s) are used as entries?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mark_Shearman
Posted On:   Thursday, April 25, 2002 07:29 AM

I have a JDialog with several JLists in JScrollPanes on it. The behaviour I would like is this:



If an entry longer than the available space is added to any of the lists, a horizontal scrollbar appears and the size of the scroll pane will not be changed.



This is exactly what happens... BUT when I close the dialog (i.e. press OK) and edit the same data later on, the JLists have ballooned in size to fit in the long Strings. Needless to say, this is very annoying.



Any ideas how I can stop this effect?



Mark

Re: How do I stop JLists from resizing when long String(s) are used as entries?

Posted By:   Sergey_Vtorov  
Posted On:   Friday, April 26, 2002 09:21 AM

You should limit the size of the JScrollPane, which contains your list.


JList list = new JList();
JScrollPane scrollPane = new JScrollPane(list);

// for layouts, which let the component to assume its preferred size
scrollPane.setPreferredSize(new Dimension(100, 200));

// or for null layout
scrollPane.setBounds(10, 10, 100, 200);
About | Sitemap | Contact