List of utility methods to do JTable Row
int | jtable$convertRowIndexToModel(JTable table, int index) jtablconvert Row Index To Model try { Method e = table.getClass().getMethod("convertRowIndexToModel", new Class[] { Integer.TYPE }); return ((Integer) e.invoke(table, new Object[] { Integer.valueOf(index) })).intValue(); } catch (Exception var3) { var3.printStackTrace(); return index; |
void | makeIntoMoveRowUpButton(final JTable table, JButton button) make Into Move Row Up Button button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int rowIndex = table.getSelectedRow(); if (rowIndex > 0) { ((DefaultTableModel) table.getModel()).moveRow(rowIndex, rowIndex, rowIndex - 1); table.setRowSelectionInterval(rowIndex - 1, rowIndex - 1); }); enableOnTableEvent(table, button); |
void | packRows(JTable table, int start, int end, int margin) pack Rows for (int r = 0; r < table.getRowCount(); r++) { int h = getPreferredRowHeight(table, r, margin); if (table.getRowHeight(r) != h) { table.setRowHeight(r, h); |
void | removeTableRows(DefaultTableModel model) remove Table Rows if (model == null) { return; int rows = model.getRowCount(); for (int i = rows - 1; i >= 0; i--) { model.removeRow(i); |
int | rowToModelIndex(JTable table, int row) row To Model Index if (row >= 0) { RowSorter<?> rowSorter = table.getRowSorter(); return rowSorter != null ? rowSorter.convertRowIndexToModel(row) : row; return -1; |
void | setRowLines(JTable table, int row, int lines) set Row Lines if (lines == 0)
lines = 1;
table.setRowHeight(row, lines * table.getRowHeight());
|
void | setTableSize(JTable table, float percentage, int rows) sets the size of the table if (table == null) { return; Integer height = rows * table.getRowHeight(); Float width = new Float(table.getPreferredSize().width * percentage); table.setPreferredScrollableViewportSize(new Dimension(width.intValue(), height)); |
void | setToRowBackground(Component c, JTable table, int row) set To Row Background dummyRenderer.getTableCellRendererComponent(table, null, false, false, row, 0);
Color bg = dummyRenderer.getBackground();
c.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue()));
|
void | updateTableSizes(JTable table, int rows) Updates the size of the table rows according to the size of the rendered component. int horizontalMargin = table.getIntercellSpacing().width; int verticalMargin = table.getIntercellSpacing().height; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int headerMaxHeight = 5; int headerMaxWidth = 0; JTableHeader header = table.getTableHeader(); if (header != null && header.isVisible()) { for (int col = 0; col < table.getColumnCount(); col++) { ... |
boolean | writeRow(DefaultTableModel table, List Writes data to the table starting from row .
String trainId = data.get(0)[0].trim(); String[] locations = data.get(1); String[] time = data.get(2); int cols = table.getColumnCount(); int counter = 0; for (int i = 0; i < locations.length; i++) { if (i - 1 >= 0) { counter += Integer.parseInt(time[i - 1].trim()); ... |