Java swing 实现下拉框和文本框同步显示

想要MyEclipse中的swing中实现下拉框和文本框实现,对下拉框创建MouseEvent、ItemEvent、ActionEvent

Java swing 实现下拉框和文本框同步显示_第1张图片

private void xingbieMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
setSelectedItem(evt, this.xingbie1);
}


private void xingbieItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
setSelectedItem(evt, this.xingbie1);
}

private void setsex1(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setSelectedItem(evt, this.xingbie1);

}

public static void setSelectedItem(AWTEvent e, JTextField ipTextField) {
JComboBox target = (JComboBox) e.getSource();
String selectedPort = (String) target.getSelectedItem();
ipTextField.setText(selectedPort);


}

 

 

更多文章请关注以下公众号

Java swing 实现下拉框和文本框同步显示_第2张图片

你可能感兴趣的:(java,swing)