Java
--
Questions
--
Followers
Top Experts
So far, I tried to add a mouse listener to my JTable, so that it'd print (just using System.out.println) the number of the clicked row. It compiles fine, but when I run the program and I click on the JTable, nothing happens.
Any idea why?
This is the code from the mouse listener:
[code]
// mouse listener to display popup JFrame with the notes belonging
// to the Task from the selected row
MouseListener ml = new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isShiftDown()||e.isCont
{
return;
}
if (e.isMetaDown())
{
int row = table.rowAtPoint(e.getPoin
System.out.println("The row number: " + row + " was clicked.") ;
}
}
};
[/code]
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
JTable jt = new JTable();
...
jt.addMouseListener(ml);
right?
Obviously my code tags aren't working
But then you only check row if a meta key is pressed, which meta do you expect to be pressed?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Yeap BobB, it's added, but still, it works only with the right button.
Do you know why?
I'm not sure if I understand you, but just in case, I tried executing the action if (e.isShiftDown()||e.isCont
But, that works only when the wheel button is pressed. That is, when you press on the mouse wheel so that it behaves like a button. But, it won't work then with either the left or right button.
Also, in case it helps at all, I'm using 1.4.2

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
That was the example I found, and I thought it was appropiate. But it seems not to be






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Selection event is fired when the table selection changes.
table.getSelectionModel().

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
OK! That's it!
Now it works, only when the left button is clicked, just the way it should:
// mouse listener to display popup JFrame with the notes belonging
// to the Task from the selected row
MouseListener ml = new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
if (e.isShiftDown()||e.isCont
{
return;
}
int row = table.rowAtPoint(e.getPoin
int col = table.columnAtPoint(e.getP
if (col == 1)
System.out.println("The row number: " + (row + 1) + " was clicked.") ;
}
}; // end of mouse listener to display pop up JFrame
Now I just have to include the popup JFrame
I've got a problem with the JFrame that I'm displaying. It contains a String with some notes, which will be quite a few words. But, at the same time, I wanted to limit the width of the JTextArea, so I used the method setColumns.
AND, when I run the program, it displays a single row; it does set the width to what I said, but there's no way I can display more than one row (and therefor, most of the text isn't display).
This is the code at the moment, anybody can see what's wrong?
MouseListener ml = new MouseAdapter()
{
public void mouseReleased(MouseEvent e)
{
if (e.isShiftDown()||e.isCont
{
return;
}
int row = table.rowAtPoint(e.getPoin
int col = table.columnAtPoint(e.getP
if (col == 1)
{
System.out.println("The row number: " + (row + 1) +
" was clicked.") ;
String testing = new String(pool.getNotes(row))
JFrame popupJFrame = new JFrame();
// JTextArea(String text, int rows, int columns)
JTextArea taskTest = new JTextArea(testing) ;
taskTest.setColumns(30) ;
taskTest.setLineWrap(true)
taskTest.setWrapStyleWord(
taskTest.setEditable(false
popupJFrame.getContentPane
popupJFrame.setLocation(ne
popupJFrame.pack() ;
popupJFrame.setResizable(f
popupJFrame.show() ;
}
}
}; // end of mouse listener to display pop up JFrame






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Java
--
Questions
--
Followers
Top Experts
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.