Problem with J Components...

Question: Why do JComboBox or JTextField ( and I pressume others ) do not work if I put them in a JWindow. They work only in a JFrame.

In jdk1.5.0 JComboBox was working properly in a JWindow as well. In the 1.6.0 it does not!

Do you know what might be the problem and what do I have to do to make it work?

Thank you!

[342 byte] By [Tyraela] at [2007-11-27 6:55:38]
# 1
When you made your original posting in the other forum you where asked to do two things:a) post a Swing related questions in the Swing forum.b) post simple code demonstrating the problemI don't see your demo code.
camickra at 2007-7-12 18:32:19 > top of Java-index,Desktop,Core GUI APIs...
# 2

package project;

import javax.swing.*;

public class Test

{

public static void main( String args[] )

{

String[] string = { "1", "2", "3" };

JComboBox box = new JComboBox( string );

JWindow window = new JWindow();

window.setLayout( new java.awt.BorderLayout() );

window.add( box, java.awt.BorderLayout.NORTH );

window.pack();

window.setVisible( true );

}

}

This is the sample code. What I am getting is a small window containing the JComboBox however when I click the drop down button it does not display the drop down list. This works in a jframe.

If I also add a "box.showPopup()" to the code it shows the dropdown list properly but it is fixed ( this is what the method does ).

What is actually happening? Do I have to implement the combobox's behavior myself or something?

Tyraela at 2007-7-12 18:32:19 > top of Java-index,Desktop,Core GUI APIs...
# 3

Did you read the JWindow API?

/*

** From the API for "JWindow(frame)" constructor:

**

** Creates a window with the specified owner frame.

** If owner is null, the shared owner will be used and this window will not be focusable.

** Also, this window will not be focusable unless its owner is showing on the screen.

*/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class WindowTest

{

public static void main(String[] args)

{

JFrame frame = new JFrame();

frame.pack();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//frame.setLocation(-200, 0); // uncomment this line to hide the dummy frame

frame.setVisible( true );

JWindow window = new JWindow(frame); // this works

//JWindow window = new JWindow(); // this doesn't work

window.getContentPane().add( new JTextField(10), BorderLayout.NORTH );

window.getContentPane().add( new JButton("Button") );

window.getContentPane().add( new JCheckBox("CheckBox"), BorderLayout.SOUTH );

window.setBounds(50, 50, 200, 200);

window.setVisible(true);

}

}

camickra at 2007-7-12 18:32:19 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thank you a lot!
Tyraela at 2007-7-12 18:32:19 > top of Java-index,Desktop,Core GUI APIs...