Mouse « JTable « Java Swing Q&A





1. How to reliably get row index in JTable from MouseEvent?    stackoverflow.com

I want to find out at whih row of JTable the user clicked. How to do it ?

2. How do I drag and drop a row in a JTable?    stackoverflow.com

How do you setup a JTable to be able to drag a row to a different index in the table. For example if I have 5 rows and I want ...

3. Setting the mouse cursor for a particular JTable cell    stackoverflow.com

I have a JTable with a set of uneditable cells and I want all the cells in a particular column to have a different mouse cursor displayed whilst the mouse is ...

4. MouseMotionListener inside JTable    stackoverflow.com

I am trying to add MouseMotion event to the label and move it based on the dragging of the mouse and make it move along with my mouse.However the mousemotion is ...

5. Use of mouselisteners in a jTable    stackoverflow.com

I have a jTable with columns 'Job_no' and 'Status'with values such as:

 Job_no       Status 
 1          ...

6. How do I add mouseClicked event to a swing table?    stackoverflow.com

I am a new, terribly green user of Swing. I managed to create a table class using examples from java.sun tutorials, and I managed to load data dynamically into it. ...

7. JTable listener problem    stackoverflow.com

I added a mouse clicked listner to my jtable, when i double click the row, will pop up an window accordingly.

jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
double amount = Double.parseDouble(jTable.getValueAt(getSelectedRow(), 4).toString());
String ...

8. Mouse event in Java    stackoverflow.com

I am trying to move a JComponent say a label over a table.I am tracking this event using MouseMotionListener's mouseDragged method.This method perfectly helps me in tracking the item.Is there a ...

9. Weird behavior of a MouseListener added to a JTable    stackoverflow.com

I've hooked up a mouse listener to a JTable to call some stuff when mouse cursor leaves table's bounds. However, mouseExited() method is also called when the mouse cursor is leaving ...





10. how to add a mouse listener to a JTable's cell holding a Boolean value rendered as checkbox    stackoverflow.com

I have a JTable with a custom model implemented extending AbstractTableModel.

public abstract class AbstractTable extends AbstractTableModel{

     public Class<? extends Object> getColumnClass(int c) {}
}
Because I've implemented the getColumnClass ...

11. Scrollbar in JScrollPane does not work on JTables    stackoverflow.com

I have a JScrollPane with number of huge JTables in it. image While i'm scrolling down the JScrollPane by mouse scroll, it just stops when the mouse pointer passes a ...

12. How to add mouse listener to a component in a custom JTable header cell renderer    stackoverflow.com

I implemented a custom header cell renderer which is used by a JTable instance.

private final class TableHeaderCellRenderer extends DefaultTableCellRenderer {
    private static final long serialVersionUID = 6288512805541476242L;

  ...

14. Detecting mouse events in JTable    coderanch.com

15. MouseListener to JTable    coderanch.com

16. complex JTable cell mouseover issue    coderanch.com

Michael, Thanks, for your assistance. I tried what you suggested. The problem seems to be that adding the mouse listener to the table isn't enough. This way, when the mouse moves from cell (0,0) to below, cell(1,0), the mouseListener is not alerted because it is still in the table (the mouseListener is attached to the table). it seems that I need ...





17. Disabling MouseEvents in JTable    coderanch.com

18. JTable not displayed when mouse clicked    coderanch.com

20. Getting mouse events for a component in a Jtable cell    coderanch.com

Hi Sarone, The problem with the JTable/JTree use of renderers is that you 'see' the labels -or whatever you put in there by overriding the getCellRendererComponent() but the objects are not reall there. The table/tree hands over its Graphics object for painting but thats all. You'll have to detect the x,y of the click to decide which label was clicked. You ...

21. Urgent: JTable cell listening to mouseClicked???    coderanch.com

Hi. I've a JTable with individual cell selection enabled. I would like selected cells to listen to mouse clicked events. WHen a user clicks on a cell, a new JFrame pops up. With my current code, *all* cells are listening to the mouseClicked event. This is wrong. Ideally I would like to use something like this, but I can't get and ...

22. Help! MouseListener/JTable Question    coderanch.com

23. JTable and Mouse Events    coderanch.com

24. Disabling mouse-click over JTable    coderanch.com

25. Consuming MouseEvent in JTable    coderanch.com

Hi All, Does event consuming works for JTable? I can't reach this with SimpleTableDemo import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class SimpleTableDemo extends JPanel { public SimpleTableDemo() { super( new GridLayout( 1, 0 ) ); String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer( ...

26. jtable right mouse click    coderanch.com

This is the only way I could find to select a row on a right mouse click: myTable.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e) { // check for right mouse click: if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { // calculate where we are in the JTable: int y = e.getY(); int row = Math.round(y / myTable.getRowHeight()); // select the row: myTable.setRowSelectionInterval(row,row); } ...

27. MouseListener on Column of a JTable    coderanch.com

28. jTable selectedRowIndex at mouse click    coderanch.com

hi ... m using Jtable..in my application i want to get the selected row index i have method getSelectedRow() but i want selected row index at click on popup menu's iteam.meaning there is a popup menu on right click at jtable having a pop up menu iteam deleteRow wen user click on this item i want to get the index of ...

29. jtable mouse click behaviour    coderanch.com

30. JTable and mouse cursor    coderanch.com

31. Regarding JTable mouse events    coderanch.com

32. MouseEvent on JTable    coderanch.com

33. Cell showing junk chars after mouse click    coderanch.com

I have a screen designed in Swing, for modifying the records in a table in Access database. The screen is working fine. There is only one column that is editable. user types some name in the column 'Player Name'. After pressing tab or clicking on other cell, the text is changing to some junk characters. However, the correct text is stored ...

34. How do I capture a mouseClicked event from a JTable within a JScrollPane    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Test extends MouseAdapter { public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] headers = {"A", "B", "C"}; Object[][] data = {{1, 2, 3}, {4, 5, 6}}; JTable table = new JTable(data, headers); JScrollPane scroll = new JScrollPane(); scroll.setViewportView(table); frame.add(scroll); frame.pack(); frame.setVisible(true); table.addMouseListener(new Test()); scroll.addMouseListener(new ...

35. Mouse Events not working in a JTable    coderanch.com

Ahhh I created a new table after adding the listener and didn't bother to add another. Thanks for the help, sorry for taking your time. For users trying to create a table with a listener, this code works. Thanks again, Bart import javax.swing.GroupLayout.*; import java.awt.event.*; import javax.swing.*; import java.awt.event.MouseEvent; public class Main extends javax.swing.JFrame{ private JScrollPane scrollPane; private JTable table; int ...

37. detect mouseclick of jtable if column renderer is also a jtable    coderanch.com

hi. id like to ask for ideas on how to detect a mouseclick on a jtable's column if its cellrenderer/editor is also a jtable thing is, clicking on other columns works ok. but if the column's renderer/editor is a jtable, id have to click on it once to have the focus on it, then click again so that the inner jtable's ...

38. jwindow, jscrollpane and jtable + mouse cursor    coderanch.com

i have a jwindow that contains a jscrollpane that contains a jtable. what i want to do is to trigger the jwindow to close when the mouse cursor is not on top of it i added a mouselistener to the jscrollpane but the method does not get called consistently this is how i did it jScrollPane1.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent ...

39. JTable with custom checkbox cell editor - problem with the table MouseListener    coderanch.com

I have a Table in which you are only supposed to be able to change the state of the checkbox if you click on the checkbox, and not if you click outside of it (note: the code right now assume that the checkbox is completely aligned to the lift, which it is not, but that has got nothing to do with ...

41. How to add mouse clicked listener on rows of a jtable    java-forums.org

Hi, I have a jtable and I want to have a mouse clicked listner on the rows of the table. I am using netbeans. If I click on the design view and on the table name ,I am unable to add events .Please let me know how can I add a mouse listener.If i try to do it via the code ...

42. JTable Not Capturing Mouse Events    forums.oracle.com

(JPanel area) (JTextArea) Person's Name: (JTextField) (User Input goes here) (JTextArea) Age (JTextField) (User Input goes here) (JTextArea) Etc. (JTextField) (User Input goes here) (JScrollpane) (Header area from String[]) Name Age Etc (JTable embedded in scrollpane) I want the user to be able to click on one of the headers in the scrollpane area to sort the JTable. Please let me ...

43. Problem with mouselistener on JTable    forums.oracle.com

Hi, I'm developing a JApplet with a "dynamic" JTable. I use a Vector of stringarrays and wrote my own tablemodel. At execution time I start with one row (and one vector-element obviously) in the JTable and when I enter a valid value in the second column of the last row, a new row appears (as it should) on the bottom of ...

44. How to make the row header of the JTable respond to mouse events?    forums.oracle.com

Is there an easy way to enable the row header of a JTable so it listens to mouse events? I have put a button in the first cell of the row header but I can't click in it. I'm asking for an easy way because I've seen some fairly complicated examples on the web that seem close to what I want ...