Double click listener on JTable in Java

Try this: mytable.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { JTable table =(JTable) mouseEvent.getSource(); Point point = mouseEvent.getPoint(); int row = table.rowAtPoint(point); if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) { // your valueChanged overridden method } } });

How to populate JTable from ResultSet?

I think the simplest way to build a model from an instance of ResultSet, could be as follows. public static void main(String[] args) throws Exception { // The Connection is obtained ResultSet rs = stmt.executeQuery(“select * from product_info”); // It creates and displays the table JTable table = new JTable(buildTableModel(rs)); // Closes the Connection JOptionPane.showMessageDialog(null, … Read more

How to get rid of the border with a JTable / JScrollPane

Use BorderFactory.createEmptyBorder() instead of null… by using: sp.setBorder(createEmptyBorder()); it works. Your main method becomes: public static void main(String[] args) { JFrame frame = new TestScrollPane(); JPanel panel = new JPanel(); JTable table = new JTable(); panel.setLayout(new BorderLayout()); panel.add(new JLabel(“NORTH”), BorderLayout.NORTH); panel.add(new JLabel(“SOUTH”), BorderLayout.SOUTH); JScrollPane sp = new JScrollPane(table); sp.setBorder(BorderFactory.createEmptyBorder()); panel.add(sp, BorderLayout.CENTER); frame.add(panel); frame.setVisible(true); }

JTable with horizontal scrollbar

First, add your JTable inside a JScrollPane and set the policy for the existence of scrollbars: new JScrollPane(myTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Then, indicate that your JTable must not auto-resize the columns by setting the AUTO_RESIZE_OFF mode: myJTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

JTable Scrolling to a Specified Row Index

It’s very easy, JTable has scrollRectToVisible method too. If you want, you can try something like this to make scrollpane go to to the bottom if a new record is added : jTable1.getSelectionModel().setSelectionInterval(i, i); jTable1.scrollRectToVisible(new Rectangle(jTable1.getCellRect(i, 0, true))); Where i is last added record.

JTable How to refresh table model after insert delete or update the data.

If you want to notify your JTable about changes of your data, use tableModel.fireTableDataChanged() From the documentation: Notifies all listeners that all cell values in the table’s rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in … Read more