日期:2014-05-20 浏览次数:20762 次
package haha;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.*;
import java.awt.event.*;
public class Tables extends JFrame implements ActionListener{
static JButton Jb=new JButton("插入");
static JPanel Jp=new JPanel(new BorderLayout());
static JTable Jt1=new JTable(10,1);
static JTable Jt2=new JTable(1,1);
public Tables()
{
setSize(800,600);
Jp.setLocation(0,0);
Jp.setSize(100,600);
add(Jp);
Jb.setLocation(50,600);
Jb.setSize(100,30);
//Jb.setBounds(100,200,50,20);
Jp.add(Jb);
//JList Jt=new JList();
Jt1.setLocation(100, 80);
Jt2.setLocation(100, 100);
Jt1.setGridColor(Color.red);
Jt2.setGridColor(Color.red);
Jt1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Jt2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Jp.add(Jt1,BorderLayout.WEST);
Jp.add(Jt2,BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
TableColumn first1Column=Jt1.getColumnModel().getColumn(0);
first1Column.setPreferredWidth(50);
first1Column.setMaxWidth(50);
first1Column.setMinWidth(50);
TableColumn first2Column=Jt2.getColumnModel().getColumn(0);
first2Column.setPreferredWidth(50);
first2Column.setMaxWidth(50);
first2Column.setMinWidth(50);
//获取Jt1,Jt2,的行数和列数
int rowc1=Jt1.getRowCount();
int colc1=Jt1.getColumnCount();
int rowc2=Jt2.getRowCount();
int colc2=Jt2.getColumnCount();
Jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==Jb){
Object tobj=0;
for(int i=0;i<10;i++)
{
tobj=Jt2.getValueAt(0,0);
for(int j=0;j<1;j++){
Jt1.setValueAt(tobj,i,j);
Jt2.clearSelection();
}
}
}
}
public static void main(String[]args)
{
new Tables();
//Jb.addActionListener(new Tables());
}
}