Mercurial > hg > RemoteEditor > REPSessionManager
view test/JTableTest.java @ 375:34642bc65c21
*** empty log message ***
author | kono |
---|---|
date | Wed, 22 Oct 2008 02:59:08 +0900 |
parents | 83790b8b8174 |
children |
line wrap: on
line source
package test; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; class JTableTest extends JFrame implements ActionListener, FocusListener, ListSelectionListener{ /** * */ private static final long serialVersionUID = 1L; private JTable tb; JTableTest() { getContentPane().setLayout(new FlowLayout()); tb = new JTable(10, 5); tb.setValueAt("AAA", 0, 0); tb.setValueAt("BBB", 1, 1); tb.setValueAt("CCC", 2, 2); tb.addFocusListener(this); JScrollPane sp = new JScrollPane(tb); sp.setPreferredSize(new Dimension(230, 80)); getContentPane().add(sp); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("JTableTest"); setSize(250, 120); setVisible(true); } public static void main(String[] args) { new JTableTest(); } public void actionPerformed(ActionEvent event) { //if(event.getSource() == tb){ // int a = tb.getSelectedColumn(); // int b = tb.getSelectedRow(); // System.out.println("Selected item is " + a + ":" + b); //} } public void focusGained(FocusEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); System.out.println("Gained item is " + column + ":" + row); } public void focusLost(FocusEvent event) { } public void valueChanged(ListSelectionEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); Object value = tb.getValueAt(row, column); System.out.println("Gained item is " + column + ":" + row + "," + value); } }