jtable

Move row with mouse in JTable

一世执手 提交于 2021-02-08 10:32:19
问题 I have JTable with some rows. I want when move one row with mouse(drag and drop) that row to move together with mouse and table rows to be reorder when mouse move(like moving JTable's columns). This jsfiddle is exactly what i want but i have to do it in java swing(or gif image below. Example is from here but I can't understand it). My TransferHandler : public class TableRowTransferHandler extends TransferHandler { private final DataFlavor localObjectFlavor = new ActivationDataFlavor(Integer

Unable to add JButtons wrapped in JPanel into JTable

北城以北 提交于 2021-02-08 09:28:14
问题 I am having a JTable , where the final column of the table is for adding 2 buttons. Below is the format of my JTable . Below is my code private class ViewLawyersDisplayData extends ComponentAdapter { @Override public void componentShown(ComponentEvent e) { dbConnector = new DBHandler(); dbConnector.makeConnection(); ResultSet rs = dbConnector.selectAllLawyerDetails(); if(rs==null) { JOptionPane.showMessageDialog(null,"The table is empty"); } else { try { while(rs.next()) { int id = rs.getInt(

Changing Dropdown content in a JTable Column in Swing

不打扰是莪最后的温柔 提交于 2021-02-08 08:42:37
问题 I have a JTable in which the first column contains combobox with same items in each cell.If i select an item in a cell combobox i need to remove the selected item from all the other combobox in that column and also add the previous selected item to all the other combobox.How should i do that?Please help me with an example. public class Save extends JFrame { String[] items1 = new String[] { "Cash", "Bank1", "Bank2" ,"Bank3"}; TableCellEditor editors; DefaultTableModel dtmFunds; private

Single click to edit a JTable Cell

走远了吗. 提交于 2021-02-07 11:26:44
问题 currently the JTable cell is selected on first click, and on the second one it is edited. Is it possible to directly edit it on the first click? 回答1: In the DefaultCellEditor api there is a method named setClickCountToStart DefaultCellEditor singleclick = new DefaultCellEditor(new JTextField()); singleclick.setClickCountToStart(1); //set the editor as default on every column for (int i = 0; i < table.getColumnCount(); i++) { table.setDefaultEditor(table.getColumnClass(i), singleclick); } 回答2:

Is there an elegant way to make JTable stop editing when user closes the application window?

南楼画角 提交于 2021-02-07 04:18:51
问题 I am trying to find out an elegant way to make JTable stop cell editing (cancel it actually) when user closes the main application window. I know something like this can be done using the WindowAdapter but for this to work properly I need a reference to the window. Problem is I sometimes do not have it. 回答1: An abrupt exit may need to be handled at several levels. Assuming that the user must navigate out of the table to click on an Exit control, you should get the desired result by setting

change color JTable cells with getTableCellRendererComponent NOTHING HAPPENDS

拥有回忆 提交于 2021-02-04 08:28:50
问题 I am trying to change the color of some cells in my JTable. I have tried to override getTableCellRendererComponent in a simple example, and it works nice. But when I do the same in my project nothing changes... I have my JPanel with my JTable in a Box like this: boxTable=Box.createHorizontalBox(); box2Table.add(boxTable); //JTable tablaContador = new JTable(datosContador,cabeceraContador); //MODIF COLOR tablaContador.setDefaultRenderer(Object.class, new ColorRenderer()); Doing: System.out

change color JTable cells with getTableCellRendererComponent NOTHING HAPPENDS

岁酱吖の 提交于 2021-02-04 08:28:05
问题 I am trying to change the color of some cells in my JTable. I have tried to override getTableCellRendererComponent in a simple example, and it works nice. But when I do the same in my project nothing changes... I have my JPanel with my JTable in a Box like this: boxTable=Box.createHorizontalBox(); box2Table.add(boxTable); //JTable tablaContador = new JTable(datosContador,cabeceraContador); //MODIF COLOR tablaContador.setDefaultRenderer(Object.class, new ColorRenderer()); Doing: System.out

Access string variable outside for loop in java?

柔情痞子 提交于 2021-01-29 05:37:41
问题 hi folks i want to access a string variable outside for loop, so that i can use it for further coding. Here i am trying to get the values from Jtable and store it in string, to create a database table. The Whole Code is here: http://textuploader.com/?p=6&id=zVEWY Coding : int row = table.getRowCount(); int column = table.getColumnCount(); for (int j = 0; j < row; j++) { for (int i = 0; i < column; i++) { //System.out.println(table.getValueAt(j, i)); String readstr = (String) table.getValueAt

How to restore column widths in a JTable?

一世执手 提交于 2021-01-29 00:40:43
问题 My question is clear. Is there any way to restore the width of the columns automatically after user has resized them? Every time the button is clicked, I want the column widths to be restored. public class TableTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); JTable table = new JTable(new Object[][] { { "something", "something else" } },

How to restore column widths in a JTable?

天大地大妈咪最大 提交于 2021-01-29 00:35:48
问题 My question is clear. Is there any way to restore the width of the columns automatically after user has resized them? Every time the button is clicked, I want the column widths to be restored. public class TableTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); JTable table = new JTable(new Object[][] { { "something", "something else" } },