JComboBox constructor: Is there a bug?
Hello everyone,
I have made a simple GUI which doesn't do much, but it works. That is to say, when I try to add a JComboBox, something goes terribly wrong. After several trial-and-error steps I pinned the problem down to this: If I do not invoke the JComboBox constructor (tried the ( ) and ( String[] ) arguments), everything works nicely. If I, however, try to invoke any of these 2 constructors, no part of my GUI works at all.
Appreciate any help, I have no idea on how to understand/solve this problem.
Paul Anton.
Source Code:
package top;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MyFrame extends JFrame implements ActionListener {
/**
* Bullshit ID to keep eclipse happy
*/
private static final long serialVersionUID = 1L;
/**
* The button that sends new settings to the scrapers
*/
private JButton applyButton;
/**
* The button to exit scraper app
*/
private JButton exitButton;
/**
* The JComboBox for setting scraper settings
*/
private JComboBox scraperSetting;
/**
* <code>MyFrame</code> constructor
* @param frameTitle
*/
public MyFrame(String frameTitle) {
/*
* Call super constructor, set basic properties
*/
super(frameTitle);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setResizable(false);
this.setLayout(new GridLayout(2,1));
this.setSize(350, 500);
JPanel topPanel = new JPanel(new GridLayout(2, 1));
topPanel.setBorder(BorderFactory.createTitledBorder("Scraper settings"));
JPanel bottomPanel = new JPanel(new GridLayout(1, 1));
bottomPanel.setBorder(BorderFactory.createTitledBorder("Exit Application"));
String[] scraperSettingStrings = {"Setting 1", "Setting 2"};
/* PROBLEM OCCURS WHEN CONSTRUCTOR IS INVOKED */
scraperSetting = new JComboBox();
/* EVERYTHING ELSE WORKS FINE!! */
//scraperSetting.setVisible(true);
//topPanel.add(scraperSetting);
applyButton = new JButton("Apply setting");
applyButton.addActionListener(this);
topPanel.add(applyButton);
this.add(topPanel);
exitButton = new JButton("Exit");
exitButton.addActionListener(this);
bottomPanel.add(exitButton);
this.add(bottomPanel);
}
/**
* <code>main</code> method
* @param args
*/
public static void main(String[] args) {
MyFrame frame = new MyFrame("Scraper Control");
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == applyButton) {
System.out.println("Setting scraper settings...");
} else if (e.getSource() == exitButton) {
System.out.println("Exiting app...");
System.exit(0);
}
}
}

