aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JScrollPane and JComboBox, loss of drop down Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollPane and JComboBox, loss of drop down" Watch "JScrollPane and JComboBox, loss of drop down" New topic
Author

JScrollPane and JComboBox, loss of drop down

Christian Cooper
Greenhorn

Joined: Jul 23, 2004
Posts: 3
Hi all,

I'm a first time poster here, so be gentle.

I have a realy strange problem...

I have a JScrollPane that contains a JPanel.
The JPanel has a VerticalFlowLayout.
This main JPanel then has several sub JPanels nested within it.
Each one of these sub JPanels has a GridBagLayout containing a JLabel and some sort of data entry control (JTextField, JTextArea, JComboBox, JCheckBox).
I have enough sub JPanels that the JScrollPane draws the vertical scroll bar.

In summary:
JScrollPane
--JPanel(VerticalFlowLayout) [main]
----JPanel(GridBagLayout) [sub]
------JLabel
------JTextField
----JPanel(GridBagLayout) [sub]
------JLabel
------JComboBox
----JPanel(GridBagLayout) [sub]
------..
----JPanel(GridBagLayout) [sub]
------..
----etc...

But as soon as I use the scroll bar, the JComboBoxes lose their drop down, the button is still there, but the popup list never appears. The data is still present as you can scroll through the values using the up and down arrow keys.
Even wierder, is that any JComboBox that is displayed without needing to scroll into view seems to have lost its popup list anyway!
I will mention, that the JComboBoxes are filled dynamically by adding entries to their model directly, rather than using the Object[] or List contructors, and frankly that seems to make things hella wierd anyway.

I have tried every combination of invalidate, validate, revalidate, repaint and pack that I can think of, I've even sacrificed some Diet Coke to the Swing Gods, but all to no avail.

Does any one have any ideas what is going on?

Thanks in advance,

Chris.

[Edit: Curses to all auto whitespace trimmers!]
[ July 23, 2004: Message edited by: Christian Cooper ]
Christian Cooper
Greenhorn

Joined: Jul 23, 2004
Posts: 3
Ok upon further investigation, the JScrollPane seems to be largely irrelivent...

As does the way that I set a model and then fill it with data after instantiation...

Examination of the source for JComboBox and DefaultComboBoxModel, would indicate that a popup list resize would be triggered by a data update.

Have I missed some piece of really obvious documentation somewhere saying "Don't ever use JComboBoxes with GridBagLayout on a JPanel", or have I just missed something really obvious?

Cheers,

Chris.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JScrollPane and JComboBox, loss of drop down