import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class ComboBoxDemo extends JPanel {
JLabel picture; public ComboBoxDemo() {
String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" }; // Create the combo box, select the pig
JComboBox petList = new JComboBox(petStrings);
petList.setSelectedIndex(4);
// Layout the demo
setLayout(new BorderLayout());
add(petList, BorderLayout.NORTH);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
} public static void main(String s[]) {
JFrame frame = new JFrame("ComboBoxDemo"); frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
frame.setContentPane(new ComboBoxDemo());
frame.pack();
frame.setVisible(true);
}
}
import java.awt.event.*;
import javax.swing.*;public class ComboBoxDemo extends JPanel {
JLabel picture; public ComboBoxDemo() {
String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" }; // Create the combo box, select the pig
JComboBox petList = new JComboBox(petStrings);
petList.setSelectedIndex(4);
// Layout the demo
setLayout(new BorderLayout());
add(petList, BorderLayout.NORTH);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
} public static void main(String s[]) {
JFrame frame = new JFrame("ComboBoxDemo"); frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
frame.setContentPane(new ComboBoxDemo());
frame.pack();
frame.setVisible(true);
}
}
不知道你用的是不是VISUAL CAFE3。0/4。0?在VISUAL CAFE中新建一个工程,选择JFC APPLICATION向导并在画面中加入JCOMBOBOX,运行时点击下箭头就可以打开下拉菜单。但是如果选择AWT APPLICATION向导并在画面中加入JCOMBOBOX,运行时点击下箭头就不能打开下拉菜单。能不能帮我想出个解决办法?
谢谢!
搞定了!
我把画面重新做了一遍,在DIALOG上放了一个JPANEL。然后把JCOMBOBOX第一个放上去。就成功了。不知道为什么成功。就象我不知道原来为什么不行一样!