You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

package com.langtech.plm.mpart;
import javax.swing.*;
import com.sun.scenario.effect.impl.hw.d3d.D3DShaderSource;
import com.teamcenter.rac.util.MessageBox;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedHashMap;
public class DialogFrame extends JDialog {
private JComboBox<String> comboBox;
private Object syncObject;
public DialogFrame(JFrame owner,JComboBox<String> comboBox,ArrayList<String> list) {
super(owner, "选择已有M", true); // 模态对话框
this.comboBox = comboBox;
this.syncObject = syncObject;
JButton button = new JButton("确定");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String selectedItem =(String) comboBox.getSelectedItem();
if(selectedItem == null || selectedItem.isEmpty()) {
MessageBox.post("请选择数据!", "提示 ", MessageBox.INFORMATION);
}else {
System.out.println("Selected Item: " + selectedItem);
list.add(selectedItem);
dispose(); // 关闭对话框
}
}
});
this.setPreferredSize(new Dimension(300,100));
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new JLabel("请选择:"));
panel.add(comboBox);
panel.add(button);
this.add(panel);
this.pack();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(owner); // 居中显示
}
}