不太想用键盘事件,不知道有没有别的方法可以实现!键盘的话可以用keyPress来监听,但是总觉得别扭!
解决方案 »
- 这个怎么通过实现TrafficLog类的hashcode和equals方法来做呢???
- 向高人请教JAVA JTable用法.
- 包和文件夹有什么区别?
- 线程同步的问题。。
- 简单问题:一个字符串,给定一个字符,取这个字符前面的字符
- UUID 重复?
- java 键盘输入
- 哪里有Java类和接口的中文帮助啊?
- 探讨一下SQLServer与JDBC的getWarnings()问题
- 大家来介绍一本你在JAVA中你认为最好的书(现在的书太杂太乱了)
- instanceof是哪个类里定义的。
- 十万火急求各位高手帮忙,要写一个能够自由添加文字的程序,文字最好能移动的,最后还要保存,我该怎么做呢?最好有代码,谢谢啦(十万火急)
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(400,300);
frame.setLayout(new BorderLayout());
frame.add(new MyTable(5,4));
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}class MyTable extends JTable{
private static final long serialVersionUID = -2880222031613028633L; public MyTable(int i, int j) {
super(5,4);
SelectionListener listener = new SelectionListener(this);
this.getColumnModel().getSelectionModel().addListSelectionListener(listener);
this.getSelectionModel().addListSelectionListener(listener);
}
}class SelectionListener implements ListSelectionListener{
private JTable table;
public SelectionListener(JTable table){
this.table = table;
} @Override
public void valueChanged(ListSelectionEvent e) {
if(!e.getValueIsAdjusting()){
System.out.println(table.getSelectedRow()+","+table.getSelectedColumn());
}
}
}