当前位置: 技术问答>java相关
关于两个JList的问题(附代码)
来源: 互联网 发布时间:2017-04-27
本文导语: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class MyFrame1 extends JFrame implements ListSelectionListener,ActionListener{ public MyFrame1(){ setTitle("Dialog test"); Toolkit tk=Toolkit.getDefaultToolkit(); Dimensio...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class MyFrame1 extends JFrame implements ListSelectionListener,ActionListener{
public MyFrame1(){
setTitle("Dialog test");
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
int screWidth=d.width;
int screHeight=d.height;
setSize(screWidth*3/5,screHeight*3/5);
setLocation(screWidth/5,screWidth/5);
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testButton=new JButton("CLICK ME");
northPanel=new JPanel();
northPanel.add(testButton);
getContentPane().add(northPanel,"North");
centerPanel=new JPanel();
model1=new DefaultListModel();
model1.addElement("quick");
model1.addElement("fat");
model1.addElement("slow");
model1.addElement("high");
model1.addElement("thin");
model1.addElement("thick");
model1.addElement("short");
list1=new JList(model1);
scrollPane1=new JScrollPane(list1);
list1.setVisibleRowCount(6);
list1.setFixedCellWidth(60);
list1.setFixedCellHeight(20);
model2=new DefaultListModel();
list2=new JList(model2);
scrollPane2=new JScrollPane(list2);
list2.setVisibleRowCount(6);
list2.setFixedCellWidth(60);
list2.setFixedCellHeight(20);
centerPanel.add(scrollPane1);
centerPanel.add(scrollPane2);
getContentPane().add(centerPanel,"Center");
southPanel=new JPanel();
viewTextField=new JTextField(20);
southPanel.add(viewTextField);
getContentPane().add(southPanel,"South");
list1.addListSelectionListener(this);
testButton.addActionListener(this);
}
public void valueChanged(ListSelectionEvent evt){
JList source = (JList)evt.getSource();
if(source==list1)
{
Object[] values=source.getSelectedValues();
for(int i=0;i
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class MyFrame1 extends JFrame implements ListSelectionListener,ActionListener{
public MyFrame1(){
setTitle("Dialog test");
Toolkit tk=Toolkit.getDefaultToolkit();
Dimension d=tk.getScreenSize();
int screWidth=d.width;
int screHeight=d.height;
setSize(screWidth*3/5,screHeight*3/5);
setLocation(screWidth/5,screWidth/5);
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testButton=new JButton("CLICK ME");
northPanel=new JPanel();
northPanel.add(testButton);
getContentPane().add(northPanel,"North");
centerPanel=new JPanel();
model1=new DefaultListModel();
model1.addElement("quick");
model1.addElement("fat");
model1.addElement("slow");
model1.addElement("high");
model1.addElement("thin");
model1.addElement("thick");
model1.addElement("short");
list1=new JList(model1);
scrollPane1=new JScrollPane(list1);
list1.setVisibleRowCount(6);
list1.setFixedCellWidth(60);
list1.setFixedCellHeight(20);
model2=new DefaultListModel();
list2=new JList(model2);
scrollPane2=new JScrollPane(list2);
list2.setVisibleRowCount(6);
list2.setFixedCellWidth(60);
list2.setFixedCellHeight(20);
centerPanel.add(scrollPane1);
centerPanel.add(scrollPane2);
getContentPane().add(centerPanel,"Center");
southPanel=new JPanel();
viewTextField=new JTextField(20);
southPanel.add(viewTextField);
getContentPane().add(southPanel,"South");
list1.addListSelectionListener(this);
testButton.addActionListener(this);
}
public void valueChanged(ListSelectionEvent evt){
JList source = (JList)evt.getSource();
if(source==list1)
{
Object[] values=source.getSelectedValues();
for(int i=0;i