List of usage examples for javax.swing JTable JTable
public JTable()
JTable
that is initialized with a default data model, a default column model, and a default selection model. From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getCellSelectionEnabled()) { table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); int rowIndex = table.getSelectedRow(); int colIndex = table.getSelectedColumn(); }//from w w w. ja v a 2 s.co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getCellSelectionEnabled()) { table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); int rowIndexStart = table.getSelectedRow(); int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex(); int colIndexStart = table.getSelectedColumn(); int colIndexEnd = table.getColumnModel().getSelectionModel().getMaxSelectionIndex(); }/*from w w w . jav a 2s . c om*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); table.setShowGrid(false);//Don't show any grid lines //Show only vertical grid lines table.setShowGrid(false);/*from ww w . j a va 2s .co m*/ table.setShowVerticalLines(true); //Show only horizontal grid lines table.setShowGrid(false); table.setShowHorizontalLines(true); //Set the grid color table.setGridColor(Color.red); //Show both horizontal and vertical grid lines (the default) table.setShowGrid(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); if (table.getCellSelectionEnabled()) { // In the other modes, the set of selected cells can be retrieved using table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // Get the min and max ranges of selected cells int rowIndexStart = table.getSelectedRow(); int rowIndexEnd = table.getSelectionModel().getMaxSelectionIndex(); int colIndexStart = table.getSelectedColumn(); int colIndexEnd = table.getColumnModel().getSelectionModel().getMaxSelectionIndex(); // Check each cell in the range for (int r = rowIndexStart; r <= rowIndexEnd; r++) { for (int c = colIndexStart; c <= colIndexEnd; c++) { if (table.isCellSelected(r, c)) { System.out.println("cell is selected"); }/*from w w w . j a v a 2s . c o m*/ } } } }
From source file:Main.java
public static void main(String[] argv) { JTable table = new JTable() { public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) { Component c = super.prepareRenderer(renderer, rowIndex, vColIndex); if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) { c.setBackground(Color.yellow); } else { c.setBackground(getBackground()); }/* w w w. j av a2 s . c om*/ return c; } }; }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable() { public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) { Component c = super.prepareRenderer(renderer, rowIndex, vColIndex); if (vColIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) { c.setBackground(Color.yellow); } else { c.setBackground(getBackground()); }/* w w w . j a v a 2s . c o m*/ return c; } }; }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); SelectionListener listener = new SelectionListener(table); table.getSelectionModel().addListSelectionListener(listener); table.getColumnModel().getSelectionModel().addListSelectionListener(listener); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable() { public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) { Component c = super.prepareRenderer(renderer, rowIndex, vColIndex); if (c instanceof JComponent) { JComponent jc = (JComponent) c; jc.setToolTipText((String) getValueAt(rowIndex, vColIndex)); }// w ww . ja v a 2 s . c o m return c; } }; }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); table.getModel().addTableModelListener(new MyTableModelListener(table)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); int vColIndex = 0; TableColumn col = table.getColumnModel().getColumn(vColIndex); col.setCellRenderer(new MyTableCellRenderer()); }