List of usage examples for javax.swing JTable getRowHeight
public int getRowHeight()
From source file:Main.java
public static void main(String[] argv) throws Exception { JTable table = new JTable(); table.setRowHeight(table.getRowHeight() + 3); }
From source file:Main.java
/** * Selects a the specified row in the specified JTable and scrolls * the specified JScrollpane to the newly selected row. More importantly, * the call to repaint() delayed long enough to have the table * properly paint the newly selected row which may be offscre * @param table should belong to the specified JScrollPane *///w ww . j a v a2 s.co m public static void selectRow(int row, JTable table, JScrollPane pane) { if (table == null || pane == null) { return; } if (contains(row, table.getModel()) == false) { return; } moveAdjustable(row * table.getRowHeight(), pane.getVerticalScrollBar()); selectRow(row, table.getSelectionModel()); // repaint must be done later because moveAdjustable // posts requests to the swing thread which must execute before // the repaint logic gets executed. repaintLater(table); }
From source file:modnlp.capte.AlignmentInterfaceWS.java
public static int getPreferredRowHeight(JTable table, int rowIndex, int margin) { // Get the current default height for all rows int height = table.getRowHeight(); // Determine highest cell in the row for (int c = 0; c < table.getColumnCount(); c++) { TableCellRenderer renderer = table.getCellRenderer(rowIndex, c); Component comp = table.prepareRenderer(renderer, rowIndex, c); int h = comp.getPreferredSize().height + 2 * margin; height = Math.max(height, h); }//w w w . j a va 2 s. c o m return height; }
From source file:JTop.java
public JTop() { super(new GridLayout(1, 0)); tmodel = new MyTableModel(); JTable table = new JTable(tmodel); table.setPreferredScrollableViewportSize(new Dimension(500, 300)); // Set the renderer to format Double table.setDefaultRenderer(Double.class, new DoubleRenderer()); // Add some space table.setIntercellSpacing(new Dimension(6, 3)); table.setRowHeight(table.getRowHeight() + 4); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to this panel. add(scrollPane);//from w w w.j a v a 2s .co m }
From source file:com.view.TradeWindow.java
private void TraderBlockOrdersActionPerformed(java.awt.event.ActionEvent evt) { TableModel dtm = (TableModel) TraderIncomingRequestsTable.getModel(); int nRow = dtm.getRowCount(); int nCol = dtm.getColumnCount(); Object[][] tableData = new Object[nRow][nCol]; ArrayList<SingleOrder> parsedOrders = new ArrayList(); ControllerBlockOrders control = new ControllerBlockOrders(); for (int i = 0; i < nRow; i++) { for (int j = 0; j < nCol; j++) { tableData[i][j] = dtm.getValueAt(i, j); }//w w w. j a v a2 s . c o m SingleOrder o = new SingleOrder(); o.SingleOrderMakeBlocks(tableData[i]); parsedOrders.add(o); } singleOrderLists = control.MakeBlock(parsedOrders); showMessageDialog(null, "Blocks have been successfully completed."); //dtm.setRowCount(0); TraderPlatformBlockedRequests.setLayout(new BorderLayout()); int count = 1; ArrayList<JScrollPane> paneList = new ArrayList<JScrollPane>(); for (ArrayList<SingleOrder> b : singleOrderLists) { JTable jTable = new JTable(); jTable.setModel(CTraderBlockOrder.getTableModel(b)); Dimension d = jTable.getPreferredSize(); // System.out.println(d); int rows = jTable.getRowCount(); // System.out.println(rows); JScrollPane jPane = new JScrollPane(); jPane.setPreferredSize(new Dimension(d.width, jTable.getRowHeight() * rows + 50)); jPane.add(jTable); jPane.setViewportView(jTable); paneList.add(jPane); count++; } test.add(blockOptions); int i = 0; for (final JScrollPane j : paneList) { // JButton btn = new JButton(); // btn.setText("Split Block"); // btn.setName(""+i); JPanel cPanel = new JPanel(); /* btn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { JViewport viewport = j.getViewport(); final JTable mytable = (JTable)viewport.getView(); final ArrayList<Integer> index = new ArrayList<Integer>(); for(int row = 0;row<mytable.getRowCount();row++){ if((boolean)mytable.getValueAt(row, 11)){ index.add(row); } } SplitBlockActionPerformed(evt,index,cPanel,test); } });*/ JCheckBox check = new JCheckBox(); JLabel label = new JLabel(); label.setText("Select Block"); check.setName("" + i); check.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SelectBlockActionPerformed(evt); } }); JPanel splitOptions = new JPanel(); splitOptions.add(label); splitOptions.add(check); splitOptions.setName("splitOpt"); // splitOptions.add(btn); cPanel.setName("cPanel" + i); cPanel.add(splitOptions); cPanel.add(j); cPanel.setLayout(new BoxLayout(cPanel, BoxLayout.Y_AXIS)); test.add(cPanel); cPanelList.add(cPanel); i++; } test.setLayout(new BoxLayout(test, BoxLayout.Y_AXIS)); JScrollPane p = new JScrollPane(test); p.setName("ParentP"); TraderPlatformBlockedRequests.add(p); TraderPlatformBlockedRequests.validate(); TraderPlatformTabbedPane.setSelectedIndex(TraderPlatformTabbedPane.getSelectedIndex() + 1); }
From source file:Visuals.BarChart.java
public JPanel addCharts() { ChartPanel barPanel = drawBarChart(); barPanel.setDomainZoomable(true);/* w ww . j av a 2s. c om*/ JPanel thisBarPanel = new JPanel(); thisBarPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, columns); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 2; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getColumnModel().getColumn(1).setPreferredWidth(600); table.getColumnModel().getColumn(2).setPreferredWidth(600); table.setShowHorizontalLines(true); table.setRowHeight(40); table.setEnabled(false); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisBarPanel.add(right, BorderLayout.EAST); thisBarPanel.add(barPanel, BorderLayout.CENTER); thisBarPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisBarPanel; }
From source file:edu.ku.brc.stats.StatGroupTable.java
/** * Calculates and sets the each column to it preferred size * @param table the table to fix ups/* w ww . j a v a 2 s . co m*/ */ public static void calcColumnWidths(JTable table) { JTableHeader header = table.getTableHeader(); TableCellRenderer defaultHeaderRenderer = null; if (header != null) { defaultHeaderRenderer = header.getDefaultRenderer(); } TableColumnModel columns = table.getColumnModel(); TableModel data = table.getModel(); int margin = columns.getColumnMargin(); // only JDK1.3 int rowCount = data.getRowCount(); int totalWidth = 0; for (int i = columns.getColumnCount() - 1; i >= 0; --i) { TableColumn column = columns.getColumn(i); int columnIndex = column.getModelIndex(); int width = -1; TableCellRenderer h = column.getHeaderRenderer(); if (h == null) h = defaultHeaderRenderer; if (h != null) // Not explicitly impossible { Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i); width = c.getPreferredSize().width; } for (int row = rowCount - 1; row >= 0; --row) { TableCellRenderer r = table.getCellRenderer(row, i); Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i); width = Math.max(width, c.getPreferredSize().width + 10); // adding an arbitray 10 pixels to make it look nicer } if (width >= 0) { column.setPreferredWidth(width + margin); // <1.3: without margin } totalWidth += column.getPreferredWidth(); } // If you like; This does not make sense for two many columns! Dimension size = table.getPreferredScrollableViewportSize(); //if (totalWidth > size.width) { size.height = Math.min(size.height, table.getRowHeight() * visibleRows); size.width = totalWidth; table.setPreferredScrollableViewportSize(size); } }
From source file:Visuals.PieChart.java
public JPanel addCharts() { ChartPanel piePanel = drawPieChart(); piePanel.setDomainZoomable(true);//from w w w . j ava2 s. c o m JPanel thisPiePanel = new JPanel(); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, columns); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 2; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getColumnModel().getColumn(1).setPreferredWidth(600); table.getColumnModel().getColumn(2).setPreferredWidth(600); JLabel right = new JLabel( " "); thisPiePanel.add(right, BorderLayout.EAST); table.setShowHorizontalLines(true); table.setRowHeight(40); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); table.setEnabled(false); thisPiePanel.setLayout(new BorderLayout()); if (riskCount == 0) { thisPiePanel.add(piePanel, BorderLayout.CENTER); } else { thisPiePanel.add(right, BorderLayout.EAST); thisPiePanel.add(piePanel, BorderLayout.CENTER); thisPiePanel.add(tableScrollPane, BorderLayout.SOUTH); } thisPiePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); return thisPiePanel; }
From source file:Visuals.RingChart.java
public JPanel addDefenceCharts() { lowValue = "Low (" + low + ")"; ChartPanel ringPanel = drawRingChart(); ringPanel.setDomainZoomable(true);//from w ww . ja va 2 s. c om JPanel thisRingPanel = new JPanel(); thisRingPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, networkDefenceColumns); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setEnabled(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int width = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, 1); Component comp = table.prepareRenderer(renderer, row, 1); width = Math.max(comp.getPreferredSize().width, width); } table.getColumnModel().getColumn(1).setPreferredWidth(width); width = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, 2); Component comp = table.prepareRenderer(renderer, row, 2); width = Math.max(comp.getPreferredSize().width, width); } table.getColumnModel().getColumn(2).setPreferredWidth(width); table.setShowHorizontalLines(true); table.setRowHeight(40); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisRingPanel.add(right, BorderLayout.EAST); thisRingPanel.add(ringPanel, BorderLayout.CENTER); thisRingPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisRingPanel; }
From source file:Visuals.RingChart.java
public JPanel addAVCharts() { JPanel thisPanel = new JPanel(); thisPanel.setLayout(new BorderLayout()); int tempCriticalCount = 0, tempUpdatedCount = 0; String[][] criticalList = new String[critical][4]; String[][] updatedList = new String[low][4]; for (int i = 0; i < riskCount; i++) { if (risks[i][2].equals("Critical")) { criticalList[tempCriticalCount][0] = risks[i][0]; criticalList[tempCriticalCount][1] = risks[i][1]; criticalList[tempCriticalCount][3] = risks[i][3]; tempCriticalCount++;//www. ja va2s .c o m } if (risks[i][2].equals("Low")) { updatedList[tempUpdatedCount][0] = risks[i][0]; updatedList[tempUpdatedCount][1] = risks[i][1]; tempUpdatedCount++; } } JTable criticalTable = new JTable(criticalList, criticalColumns); JTable updatedTable = new JTable(updatedList, updatedColumns); TableColumn tcol = criticalTable.getColumnModel().getColumn(2); criticalTable.removeColumn(tcol); TableColumn tcol2 = updatedTable.getColumnModel().getColumn(2); updatedTable.removeColumn(tcol2); criticalTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); updatedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); criticalTable.setEnabled(false); updatedTable.setEnabled(false); int width = 0; for (int i = 0; i < 3; i++) { for (int row = 0; row < criticalTable.getRowCount(); row++) { TableCellRenderer renderer = criticalTable.getCellRenderer(row, i); Component comp = criticalTable.prepareRenderer(renderer, row, i); width = Math.max(comp.getPreferredSize().width, width); } criticalTable.getColumnModel().getColumn(i).setPreferredWidth(width); width = 0; } for (int i = 0; i < 2; i++) { for (int row = 0; row < updatedTable.getRowCount(); row++) { TableCellRenderer renderer = updatedTable.getCellRenderer(row, i); Component comp = updatedTable.prepareRenderer(renderer, row, i); width = Math.max(comp.getPreferredSize().width, width); } updatedTable.getColumnModel().getColumn(i).setPreferredWidth(width); width = 0; } criticalTable.setShowHorizontalLines(true); criticalTable.setRowHeight(40); updatedTable.setShowHorizontalLines(true); updatedTable.setRowHeight(40); JScrollPane criticalTableScrollPane = new JScrollPane(criticalTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JScrollPane updatedTableScrollPane = new JScrollPane(updatedTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = criticalTable.getPreferredSize(); criticalTableScrollPane.setPreferredSize( new Dimension((d.width - 400), (criticalTable.getRowHeight() + 1) * (tempCriticalCount + 1))); Dimension d2 = updatedTable.getPreferredSize(); updatedTableScrollPane.setPreferredSize( new Dimension((d.width - 400), (updatedTable.getRowHeight() + 1) * (tempUpdatedCount + 1))); Font titleFonts = new Font("Calibri", Font.BOLD, 30); JLabel criticalLabel = new JLabel(" Critical "); criticalLabel.setFont(titleFonts); criticalLabel.setForeground(new Color(230, 27, 27)); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); leftPanel.add(criticalLabel, BorderLayout.WEST); leftPanel.add(criticalTableScrollPane, BorderLayout.CENTER); JLabel updatedLabel = new JLabel(" Updated "); updatedLabel.setFont(titleFonts); updatedLabel.setForeground(new Color(47, 196, 6)); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BorderLayout()); rightPanel.add(updatedLabel, BorderLayout.WEST); rightPanel.add(updatedTableScrollPane, BorderLayout.CENTER); if (tempCriticalCount != 0) thisPanel.add(leftPanel, BorderLayout.NORTH); if (tempUpdatedCount != 0) thisPanel.add(rightPanel, BorderLayout.SOUTH); return thisPanel; }