HMH
HMH

Reputation: 33

JCombobox unexpected behaviour

I have designed a JFrame in Netbeans as shown in the image below:

http://tinypic.com/r/2em2wxd/8

When I run the program, the combo box goes all white as shown in the image below:

http://tinypic.com/r/2vblwuf/8

And.. When I click the "white" space it shows the Item(s) inside the combo box which can be selected.. but even after selecting, it is still the same white space not showing the layout properly and the selected item.

My code is as following:

public class LoginWindow extends javax.swing.JFrame {

/**
 * Creates new form LoginWindow
 */
public LoginWindow() {
    initComponents();
    setLocationRelativeTo(null);

    new MyWorker().execute();
}
..........

And the Worker class is as following:

    class MyWorker extends javax.swing.SwingWorker<String, Void> {

    protected String doInBackground() {
        databaseCheck();
        return "done";
    }

    protected void done() {
        progressPanel.setVisible(false);
        loginPasswordField.setEnabled(true);
        locationComboBox.setEnabled(true);
        loginButton.setEnabled(true);
        loginPasswordField.requestFocusInWindow();
    }
}

It must be noted that this behaviour is mostly experienced, although sometimes it is working just fine (very rarely)... Any help would be appreciated.

Upvotes: 0

Views: 53

Answers (1)

HMH
HMH

Reputation: 33

I just seemed to have fixed it while trying to post an SSCCE..

The actual component size visible on the frame was [256, 29].. whereas the preferredSize was different which seemed to have caused the problem.

    locationComboBox.setPreferredSize(new java.awt.Dimension(256, 29));

This fixed the problem.

Upvotes: 2

Related Questions