List of usage examples for javax.swing JTable setRowHeight
@BeanProperty(description = "The height of the specified row.") public void setRowHeight(int rowHeight)
rowHeight
, revalidates, and repaints. 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 av a 2s .c o m }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);/*from w w w . ja v a 2s . co m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
From source file:com.diversityarrays.kdxplore.trials.PlotCellRenderer.java
public void updateTableRowHeight(JTable table) { FontMetrics fm = getFontMetrics(getFont()); int lineHeight = fm.getMaxAscent() + fm.getMaxDescent(); int rowHeight = lineHeight * (3 + attributeNames.size() + 1 + traitInstancesByTraitId.size()); table.setRowHeight(rowHeight); }
From source file:TableCellRenderTest.java
public TableCellRenderFrame() { setTitle("TableCellRenderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new PlanetTableModel(); JTable table = new JTable(model); table.setRowSelectionAllowed(false); // set up renderers and editors table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); table.setDefaultEditor(Color.class, new ColorTableCellEditor()); JComboBox moonCombo = new JComboBox(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i);// w w w. j a v a 2 s. c o m TableColumnModel columnModel = table.getColumnModel(); TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN); moonColumn.setCellEditor(new DefaultCellEditor(moonCombo)); moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class)); moonColumn.setHeaderValue(new ImageIcon("Moons.gif")); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
From source file:Visuals.BarChart.java
public JPanel addCharts() { ChartPanel barPanel = drawBarChart(); barPanel.setDomainZoomable(true);/*from w w w. j a v a 2 s.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:UI.SecurityDashboard.java
private void performMetric9() { GZDecompression m9 = new GZDecompression(); String[][] counts = m9.getMetric9(); Font titleFont = new Font("Calibri", Font.BOLD, 27); JLabel logAuditTitleLabel = new JLabel(" Log Audit"); logAuditTitleLabel.setFont(titleFont); AreaChart areaChart = new AreaChart(m9.getLogCount(), m9.getSuccessCount(), m9.getFailCount()); ChartPanel thisChart = areaChart.drawAreaChart(); thisChart.setBackground(Color.white); thisChart.addChartMouseListener(new ChartMouseListener() { @Override//from ww w . j a v a 2s . c o m public void chartMouseClicked(ChartMouseEvent cme) { dashboardTabs.setSelectedIndex(9); } @Override public void chartMouseMoved(ChartMouseEvent cme) { } }); Metric9Panel.setBackground(Color.WHITE); Metric9Panel.setLayout(new BorderLayout()); Metric9Panel.add(logAuditTitleLabel, BorderLayout.NORTH); Metric9Panel.add(thisChart, BorderLayout.CENTER); Metric9Panel.setEnabled(false); String[] columns = { "Log Failure" }; JTable table = new JTable(counts, columns); table.setShowHorizontalLines(true); table.setRowHeight(40); table.setEnabled(false); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); AuditPanel.setLayout(new BorderLayout()); JTextArea header = new JTextArea( "\nThrough the analysis of security logs, this page will show an audit of the attack attempts and " + "security breaches. The logs provide critical information related to system events that can be used to track suspicicous " + "activities.\n"); header.setLineWrap(true); header.setWrapStyleWord(true); header.setEditable(false); AuditPanel.add(header, BorderLayout.NORTH); AuditPanel.add(tableScrollPane, BorderLayout.CENTER); }
From source file:Visuals.PieChart.java
public JPanel addCharts() { ChartPanel piePanel = drawPieChart(); piePanel.setDomainZoomable(true);/*from w ww. j av a2s . 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 ww w.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:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java
private JTable createTable(DefaultTableModel resultsTableModel, final List<List<Color>> rowColors) { JTable table = new JTable(resultsTableModel) { public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int colIndex) { Component c = super.prepareRenderer(renderer, rowIndex, colIndex); final Color bgColor = isCellSelected(rowIndex, colIndex) ? getSelectionBackground() : rowColors.get(rowIndex).get(colIndex); c.setBackground(bgColor);/*from ww w .j a va 2s . c o m*/ return c; } }; DefaultTableCellRenderer tcr = getTableCellRenderer();//model.getRowInfoList()); for (int i = 0; i < resultsTableModel.getColumnCount(); i++) { if (resultsTableModel.getColumnClass(i) != Boolean.class) { table.setDefaultRenderer(resultsTableModel.getColumnClass(i), tcr); } } table.setCellSelectionEnabled(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); UIHelper.makeTableHeadersCentered(table, false); table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); table.setRowHeight(ROW_HEIGHT); autoResizeColWidth(table, resultsTableModel); return table; }
From source file:MainClass.java
public MainClass() { super("Table With DefaultCellEditor Example"); setSize(500, 300);/*from ww w . j a v a 2s.co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); JTable table = new JTable(new AbstractTableModel() { ColorName data[] = { colors[0], colors[1], colors[2], colors[3], colors[4], colors[0], colors[1], colors[2], colors[3], colors[4] }; public int getColumnCount() { return 3; } public int getRowCount() { return 10; } public Object getValueAt(int r, int c) { switch (c) { case 0: return (r + 1) + "."; case 1: return "Some pithy quote #" + r; case 2: return data[r]; } return "Bad Column"; } public Class getColumnClass(int c) { if (c == 2) return ColorName.class; return String.class; } public boolean isCellEditable(int r, int c) { return c == 2; } public void setValueAt(Object value, int r, int c) { data[r] = (ColorName) value; } }); table.setDefaultEditor(ColorName.class, new DefaultCellEditor(new JComboBox(colors))); table.setDefaultRenderer(ColorName.class, new DefaultTableCellRenderer()); table.setRowHeight(20); getContentPane().add(new JScrollPane(table)); }