Strange: ComboBox not moving when it should

I've discovered strange behaviour.

I have modal JFrame, in which I have JPanel which contains group of our own combo classes which extend JComboBox.

When border of the frame is closer to lowest combo box, than border of combo box when it's open, combo box works fine.

However, when I change height of JFrame so that its bottom border is further from combo box than border of lowest combo box when it's open, combo box starts behaving strangely. When I drag its scrollpad and move it up and down (to see items in Combo box), content moves ok, but scrollpad stays fixed on one place (instead of going up and down too).

Would anybody have an idea why it doesn't work ?

- there are 15 items in combo.

- we use JDK 1.5.0_10 on WinXP

[775 byte] By [sankotma] at [2007-11-27 4:18:59]
# 1
> our own combo classes which extend JComboBox. same as the response to your cross-post in c.l.j.g, the problem is likely to be in your customized code, which you haven't shown
Michael_Dunna at 2007-7-12 9:25:52 > top of Java-index,Desktop,Core GUI APIs...
# 2

> Would anybody have an idea why it doesn't work ?

You have a custom component. We have no idea what your code looks like so no I don't know what is wrong.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-12 9:25:52 > top of Java-index,Desktop,Core GUI APIs...
# 3

It happens that programming problems are caused by common causes for discovering of which, it's not allways necessary to have exact source code at hand. Therefore I've asked about my problem without source code.

As it seems that problem I've described is not of a general nature that others have experienced before, I'll provide example code. It will take some time to produce it as it's compplex system we've got for maintenance couple weeks ago, and I'm not completely familiar with alll the inner dependencies yet.

sankotma at 2007-7-12 9:25:52 > top of Java-index,Desktop,Core GUI APIs...
# 4

Here you go,

Premises we have:

- we need to implement modal window

- we have to use JInternalFrame for modal window (can't use JDialog)

Problem:

Popup part of Combobox in JInternalFrame in GlassPane doesn't scroll.

Remark:

In code I had to set combobox.setLightWeightPopupEnabled(false), cause popup part of it wouldn't show otherwise.

Code (3 files) in next post.

sankotma at 2007-7-12 9:25:52 > top of Java-index,Desktop,Core GUI APIs...
# 5

test\best\TestApp3.java

package test.best;

import java.awt.Dimension;

import java.awt.Toolkit;

import javax.swing.JFrame;

import javax.swing.UIManager;

public class TestApp3 {

public TestApp3() {

JFrame frame = new TestFrame3();

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

frame.setVisible(true);

}

public static void main(String[] args) {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (Exception e) {

e.printStackTrace();

}

new TestApp3();

}

}

test\best\TestFrame3.java

package test.best;

import cor.no.exception.CommonException;

import java.awt.Color;

import java.awt.Component;

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JComponent;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class TestFrame3 extends JFrame {

private JComboBox jComboBox1 = new JComboBox(new String[]{"Indicates","a","window","is","currently","the","active","window","Indicates","a","window","is","currently","the","active","window"});

private JLabel jLabel1 = new JLabel();

private JButton jButton1 = new JButton();

public TestFrame3() {

try {

jbInit();

} catch (Exception e) {

e.printStackTrace();

}

}

private void jbInit() throws Exception {

this.getContentPane().setLayout( null );

this.setSize(new Dimension(726, 458));

jComboBox1.setBounds(new Rectangle(200, 60, 140, 25));

jLabel1.setText("Back Combo");

jLabel1.setBounds(new Rectangle(45, 65, 110, 20));

jButton1.setText("Cover us with Glass");

jButton1.setBounds(new Rectangle(70, 125, 235, 30));

jButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jButton1_actionPerformed(e);

}

});

this.getContentPane().add(jButton1, null);

this.getContentPane().add(jLabel1, null);

this.getContentPane().add(jComboBox1, null);

}

private void jButton1_actionPerformed(ActionEvent e) {

JComponent glassPane = (JComponent)this.getGlassPane();

glassPane.setOpaque(true);

glassPane.setBackground(Color.RED); // so that you can see that it's there

glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // so that you can see that it's there

glassPane.addMouseListener(new MouseAdapter(){}); // ignores all mouse events

TestInternalFrame3 tif = null;

tif = new TestInternalFrame3();

tif.setParentGlassPane(glassPane); // so that we can get rid of glass pane when internal frame is closed

tif.setPreferredSize(new Dimension(400,400));

tif.setLocation(0,100);

tif.setResizable(true);

tif.setVisible(true);

glassPane.add(tif);

glassPane.setVisible(true);

}

}

test\best\TestInternalFrame3.java

package test.best;

import java.awt.BorderLayout;

import java.awt.Rectangle;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JComponent;

import javax.swing.JInternalFrame;

import javax.swing.JPanel;

public class TestInternalFrame3 extends JInternalFrame {

private JPanel jPanel1 = new JPanel();

private JComboBox jComboBox1 = new JComboBox(new String[]{"The","glass","pane","is","useful","when","you","want","to","be","able","to","catch","events","or","paint","over","an","area","that","already","contains","one","or","more","components"});

private JButton jButton1 = new JButton();

private JComponent glassPane = null;

public TestInternalFrame3() {

try {

jbInit();

} catch (Exception e) {

e.printStackTrace();

}

}

private void jbInit() throws Exception {

this.setTitle( "Test Internal Frame 3" );

jPanel1.setLayout(null);

jComboBox1.setBounds(new Rectangle(105, 90, 165, 25));

jComboBox1.setLightWeightPopupEnabled(false); // popup won't show otherwise !!!!

jButton1.setText("Close modal window");

jButton1.setBounds(new Rectangle(140, 160, 88, 29));

jButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jButton1_actionPerformed(e);

}

});

jPanel1.add(jButton1, null);

jPanel1.add(jComboBox1, null);

this.getContentPane().add(jPanel1, BorderLayout.CENTER);

}

private void jButton1_actionPerformed(ActionEvent e) {

this.dispose();

this.glassPane.setVisible(false);

}

public void setParentGlassPane(JComponent glassPane){

this.glassPane = glassPane;

}

}

sankotma at 2007-7-12 9:25:52 > top of Java-index,Desktop,Core GUI APIs...