展开全部
//类名 MyMouseLister
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class MyMouseLister implements MouseListener{
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
}
//类名OnMouseOver
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class OnMouseOver extends MyMouseLister{
private JLabel test1;
private JLabel test2;
private JLabel test3;
private JLabel test4;
private JPanel p;
private JFrame f;
public OnMouseOver(){
test1 = new JLabel("test1.text");
test1.addMouseListener(this);
test2 = new JLabel("test2.text");
test2.addMouseListener(this);
test3 = new JLabel("test3.text");
test3.addMouseListener(this);
test4 = new JLabel("test4.text");
test4.addMouseListener(this);
p = new JPanel(new GridLayout(2,2));
p.add(test1,0);
p.add(test2,1);
p.add(test3,2);
p.add(test4,3);
f = new JFrame("Test");
f.add(p);
f.setVisible(true);
f.setBounds(300, 200, 300, 200);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//事件可以自己换
public void mouseEntered(MouseEvent e) {
if(e.getSource() == test1){
System.out.println(test1.getText());
}else if(e.getSource() == test2){
System.out.println(test2.getText());
}else if(e.getSource() == test3){
System.out.println(test3.getText());
}else if(e.getSource() == test4){
System.out.println(test4.getText());
}
}
public static void main(String[] args) {
new OnMouseOver();
}
}
希望能帮到你虽然这个是JLabel但是道理是相通的,你看看就明白了。
//附上操作表格的方法:
getSelectedColumn()返回列索引
getSelectedRow()返回行索引
getValueAt()返回单元格的值
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class MyMouseLister implements MouseListener{
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
}
//类名OnMouseOver
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class OnMouseOver extends MyMouseLister{
private JLabel test1;
private JLabel test2;
private JLabel test3;
private JLabel test4;
private JPanel p;
private JFrame f;
public OnMouseOver(){
test1 = new JLabel("test1.text");
test1.addMouseListener(this);
test2 = new JLabel("test2.text");
test2.addMouseListener(this);
test3 = new JLabel("test3.text");
test3.addMouseListener(this);
test4 = new JLabel("test4.text");
test4.addMouseListener(this);
p = new JPanel(new GridLayout(2,2));
p.add(test1,0);
p.add(test2,1);
p.add(test3,2);
p.add(test4,3);
f = new JFrame("Test");
f.add(p);
f.setVisible(true);
f.setBounds(300, 200, 300, 200);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//事件可以自己换
public void mouseEntered(MouseEvent e) {
if(e.getSource() == test1){
System.out.println(test1.getText());
}else if(e.getSource() == test2){
System.out.println(test2.getText());
}else if(e.getSource() == test3){
System.out.println(test3.getText());
}else if(e.getSource() == test4){
System.out.println(test4.getText());
}
}
public static void main(String[] args) {
new OnMouseOver();
}
}
希望能帮到你虽然这个是JLabel但是道理是相通的,你看看就明白了。
//附上操作表格的方法:
getSelectedColumn()返回列索引
getSelectedRow()返回行索引
getValueAt()返回单元格的值
展开全部
JTable没有返回整行的方法,只有返回单元格的方法,其中有几个方法需要用到:
getSelectedColumn()返回列索引
getSelectedRow()返回行索引
getValueAt()返回单元格的值
如果需要返回第一行所有的值
1:建一个数组,假如引用名为a
2:for(int i=0;i<7;i++) {
a[i]=jTable.getValueAt(jTable.getSelectedRow(0),jTable.getSelectedColumn(i))
}
getSelectedColumn()返回列索引
getSelectedRow()返回行索引
getValueAt()返回单元格的值
如果需要返回第一行所有的值
1:建一个数组,假如引用名为a
2:for(int i=0;i<7;i++) {
a[i]=jTable.getValueAt(jTable.getSelectedRow(0),jTable.getSelectedColumn(i))
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JTable有名叫convertRowIndexToModel(int viewRowIndex)和convertColumnIndexToModel(int viewColumnIndex)的两个方法,你可以调用它得到JTable数据模型中对应的数据。至于viewRowIndex和viewColumnIndex的来源,你可以调用JTable的rowAtPoint(Point point)、columnAtPoint(Point point)来获取。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
onclick事件可以得一此行的ID,根据ID可以查询此行的数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询