Java 下拉框 JComboBox 出现重复 求大神救救我
这是一个按钮的监听会打开一个对话框其中有下拉框,关掉再打开之后下拉框就会有重复选项set.addActionListener(newActionListener(){St...
这是一个按钮的监听 会打开一个对话框 其中有下拉框,关掉再打开之后下拉框就会
有重复选项set.addActionListener(
new ActionListener() {
String fn="";
int ff=0;
int fb=0;
JComboBox comBox=new JComboBox();
JComboBox comBox1=new JComboBox();
JComboBox comBox2=new JComboBox();
JPanel setPanel=new JPanel();
JLabel f1=new JLabel("字体");
JLabel f2=new JLabel("字形");
JLabel f3=new JLabel("大小");
String fontName[];
JButton sure=new JButton("确定");
public void actionPerformed(ActionEvent e) {
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
fontName=ge.getAvailableFontFamilyNames();
for(int i=0;i<fontName.length;i++){
comBox.addItem(fontName[i]);}
String a[]= {"常规","加粗","倾斜","加粗倾斜"};
for(int i=0;i<=3;i++){
comBox1.addItem(a[i]);}
final int s[]= {10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85};
for(int i=0;i<s.length;i++) {
comBox2.addItem(s[i]);}
setPanel.add(f1);
setPanel.add(comBox);
setPanel.add(f2);
setPanel.add(comBox1);
setPanel.add(f3);
setPanel.add(comBox2);
setPanel.add(sure);
comBox.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index=comBox.getSelectedIndex();
fn=fontName[index];
System.out.print(fn);}});
comBox1.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index=comBox1.getSelectedIndex();
ff=index;
System.out.print(ff);}});
JDialog dialog=new JDialog();
dialog.setResizable(false);
dialog.setModal(true);
dialog.add(setPanel);
dialog.setBounds(470, 300, 500, 200);
dialog.setVisible(true);}} );
另外求问JTextArea文本区怎么设置对齐方式? 展开
有重复选项set.addActionListener(
new ActionListener() {
String fn="";
int ff=0;
int fb=0;
JComboBox comBox=new JComboBox();
JComboBox comBox1=new JComboBox();
JComboBox comBox2=new JComboBox();
JPanel setPanel=new JPanel();
JLabel f1=new JLabel("字体");
JLabel f2=new JLabel("字形");
JLabel f3=new JLabel("大小");
String fontName[];
JButton sure=new JButton("确定");
public void actionPerformed(ActionEvent e) {
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
fontName=ge.getAvailableFontFamilyNames();
for(int i=0;i<fontName.length;i++){
comBox.addItem(fontName[i]);}
String a[]= {"常规","加粗","倾斜","加粗倾斜"};
for(int i=0;i<=3;i++){
comBox1.addItem(a[i]);}
final int s[]= {10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85};
for(int i=0;i<s.length;i++) {
comBox2.addItem(s[i]);}
setPanel.add(f1);
setPanel.add(comBox);
setPanel.add(f2);
setPanel.add(comBox1);
setPanel.add(f3);
setPanel.add(comBox2);
setPanel.add(sure);
comBox.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index=comBox.getSelectedIndex();
fn=fontName[index];
System.out.print(fn);}});
comBox1.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index=comBox1.getSelectedIndex();
ff=index;
System.out.print(ff);}});
JDialog dialog=new JDialog();
dialog.setResizable(false);
dialog.setModal(true);
dialog.add(setPanel);
dialog.setBounds(470, 300, 500, 200);
dialog.setVisible(true);}} );
另外求问JTextArea文本区怎么设置对齐方式? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询