试试这个import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.*;public class MComboButton extends JFrame {
public MComboButton() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
} private void jbInit() throws Exception {
getContentPane().setLayout(null);
jComboBox1.setBounds(new Rectangle(20, 20, 100, 20));
jComboBox1.addItem("A");
jComboBox1.addItem("B");
this.getContentPane().add(jComboBox1);
jComboBox1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (jComboBox1.getItemCount() != 0) {
String sTemp = jComboBox1.getSelectedItem().toString();
jComboBox2.removeAllItems();
jComboBox2.addItem(sTemp + "A");
jComboBox2.addItem(sTemp + "B");
jComboBox2.setSelectedIndex(0);
}
}
});
jComboBox2.setBounds(new Rectangle(140, 20, 100, 20));
jComboBox2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (jComboBox2.getItemCount() != 0) {
String sTemp = jComboBox2.getSelectedItem().toString();
jComboBox3.removeAllItems();
jComboBox3.addItem(sTemp + "A");
jComboBox3.addItem(sTemp + "B");
jComboBox3.setSelectedIndex(0);
}
}
});
this.getContentPane().add(jComboBox2);
jComboBox3.setBounds(new Rectangle(260, 20, 100, 20));
this.getContentPane().add(jComboBox3);
} public static void main(String[] args) {
MComboButton mcombobutton = new MComboButton();
mcombobutton.setSize(380, 100);
mcombobutton.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mcombobutton.show();
} JComboBox jComboBox1 = new JComboBox();
JComboBox jComboBox2 = new JComboBox();
JComboBox jComboBox3 = new JComboBox();}
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.*;public class MComboButton extends JFrame {
public MComboButton() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
} private void jbInit() throws Exception {
getContentPane().setLayout(null);
jComboBox1.setBounds(new Rectangle(20, 20, 100, 20));
jComboBox1.addItem("A");
jComboBox1.addItem("B");
this.getContentPane().add(jComboBox1);
jComboBox1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (jComboBox1.getItemCount() != 0) {
String sTemp = jComboBox1.getSelectedItem().toString();
jComboBox2.removeAllItems();
jComboBox2.addItem(sTemp + "A");
jComboBox2.addItem(sTemp + "B");
jComboBox2.setSelectedIndex(0);
}
}
});
jComboBox2.setBounds(new Rectangle(140, 20, 100, 20));
jComboBox2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (jComboBox2.getItemCount() != 0) {
String sTemp = jComboBox2.getSelectedItem().toString();
jComboBox3.removeAllItems();
jComboBox3.addItem(sTemp + "A");
jComboBox3.addItem(sTemp + "B");
jComboBox3.setSelectedIndex(0);
}
}
});
this.getContentPane().add(jComboBox2);
jComboBox3.setBounds(new Rectangle(260, 20, 100, 20));
this.getContentPane().add(jComboBox3);
} public static void main(String[] args) {
MComboButton mcombobutton = new MComboButton();
mcombobutton.setSize(380, 100);
mcombobutton.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mcombobutton.show();
} JComboBox jComboBox1 = new JComboBox();
JComboBox jComboBox2 = new JComboBox();
JComboBox jComboBox3 = new JComboBox();}
还有一点,上面的程序在1.3下运行时,点出列表后点其中一项时(mousePressed)下面的窗体会失去焦点,再mouseReleased时窗体恢复焦点,而1.4的窗体一直有焦点,这难道就是传说中的升级版本的改进??