Java Code Examples for javax.swing.JTable#getRowHeight()
The following examples show how to use
javax.swing.JTable#getRowHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TablePagePanel.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public void customise(JTable table, JTextArea component, String value, int rowIndex, int colIndex) { if (!wrappingRows.contains(rowIndex)) { return; } component.setLineWrap(true); component.setWrapStyleWord(true); int max = 230; // if ((table).getCellSpanAt(rowIndex, colIndex).getColumnSpan() == table.getColumnCount()) { // max *= 2; // } int numRows = countLines(component, value, max); if (numRows > 1) { int rowHeight = table.getRowHeight() * numRows; table.setRowHeight(rowIndex, Math.max(table.getRowHeight(rowIndex), rowHeight)); } }
Example 2
Source File: MapRuleRender.java From finalspeed-91yun with GNU General Public License v2.0 | 6 votes |
void update(MapRule rule,JTable table,int row){ this.rule=rule; int rowHeight=50; int h=table.getRowHeight(row); if(h!=rowHeight){ table.setRowHeight(row, rowHeight); } String name=rule.getName(); if(name==null){ name="无"; }else if(name.trim().equals("")){ name="无"; } label_wan_address.setText("名称: "+rule.name+" 加速端口: "+rule.dst_port); label2.setText("本地端口: "+rule.getListen_port()); }
Example 3
Source File: ObjectivePanel.java From triplea with GNU General Public License v3.0 | 6 votes |
@Override public Component getTableCellRendererComponent( final JTable table, final Object obj, final boolean isSelected, final boolean hasFocus, final int row, final int column) { // set the colors, etc. using the standard for that platform adaptee.getTableCellRendererComponent(table, obj, isSelected, hasFocus, row, column); setForeground(adaptee.getForeground()); setBackground(adaptee.getBackground()); setBorder(adaptee.getBorder()); setFont(adaptee.getFont()); setText(adaptee.getText()); // This line was very important to get it working with JDK1.4 final TableColumnModel columnModel = table.getColumnModel(); setSize(columnModel.getColumn(column).getWidth(), 100000); int heightWanted = (int) getPreferredSize().getHeight(); addSize(table, row, column, heightWanted); heightWanted = findTotalMaximumRowSize(table, row); if (heightWanted != table.getRowHeight(row)) { table.setRowHeight(row, heightWanted); } return this; }
Example 4
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
private static Rectangle fitToScreen(@NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) { Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim); ScreenUtil.fitToScreen(rectangle); if (rectangle.getHeight() != newDim.getHeight()) { int newHeight = (int) rectangle.getHeight(); int roundedHeight = newHeight - newHeight % table.getRowHeight(); rectangle.setSize((int) rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight())); } return rectangle; }
Example 5
Source File: GuiUtil.java From CQL with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("serial") public static JPanel makeTable(Border b, String border, Object[][] rowData, Object... colNames) { JTable t = new JTable(rowData, colNames) { @Override public Dimension getPreferredScrollableViewportSize() { Dimension d = getPreferredSize(); return new Dimension(Integer.max(640, d.width), (d.height)); } }; JPanel p = new JPanel(new GridLayout(1, 1)); TableRowSorter<?> sorter = new MyTableRowSorter(t.getModel()); if (colNames.length > 0) { sorter.toggleSortOrder(0); } t.setRowSorter(sorter); sorter.allRowsChanged(); p.add(new JScrollPane(t)); for (int row = 0; row < t.getRowCount(); row++) { int rowHeight = t.getRowHeight(); for (int column = 0; column < t.getColumnCount(); column++) { Component comp = t.prepareRenderer(t.getCellRenderer(row, column), row, column); rowHeight = Math.max(rowHeight, comp.getPreferredSize().height); } t.setRowHeight(row, rowHeight); } Font font = UIManager.getFont("TableHeader.font"); p.setBorder(BorderFactory.createTitledBorder(b, border, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, font, Color.black)); return p; }
Example 6
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
private static Rectangle fitToScreen(@NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) { Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim); ScreenUtil.fitToScreen(rectangle); if (rectangle.getHeight() != newDim.getHeight()) { int newHeight = (int)rectangle.getHeight(); int roundedHeight = newHeight - newHeight % table.getRowHeight(); rectangle.setSize((int)rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight())); } return rectangle; }
Example 7
Source File: ItemListImageViewerEvent.java From stendhal with GNU General Public License v2.0 | 5 votes |
/** * Adjust the row heights of a table based on the table contents. * * @param table adjusted table */ private void adjustRowHeights(JTable table) { for (int row = 0; row < table.getRowCount(); row++) { int rowHeight = table.getRowHeight(); for (int column = 0; column < table.getColumnCount(); column++) { Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column); rowHeight = Math.max(rowHeight, comp.getPreferredSize().height); } table.setRowHeight(row, rowHeight); } }
Example 8
Source File: Table.java From Spark with Apache License 2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(JTable jTable, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { // set color & border here setText(obj == null ? "" : obj.toString()); setSize(jTable.getColumnModel().getColumn(column).getWidth(), getPreferredSize().height); if (jTable.getRowHeight(row) != getPreferredSize().height) { jTable.setRowHeight(row, getPreferredSize().height); } return this; }
Example 9
Source File: UiUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static void configureRowHeight(JTable table) { int height = table.getRowHeight(); Font cellFont = UIManager.getFont("TextField.font"); if (cellFont != null) { FontMetrics metrics = table.getFontMetrics(cellFont); if (metrics != null) { height = metrics.getHeight() + 2; } } table.setRowHeight(Math.max(table.getRowHeight(), height)); }
Example 10
Source File: VariablesWindow.java From cstc with GNU General Public License v3.0 | 5 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Dimension preferredSize = getPreferredSize(); setText(value.toString()); setSize(preferredSize.width, getPreferredSize().height); if (table.getRowHeight(row) != getPreferredSize().height) { table.setRowHeight(row, getPreferredSize().height); } setColumnWidth(preferredSize); return this; }
Example 11
Source File: TableDemo.java From littleluck with Apache License 2.0 | 4 votes |
protected void initComponents() { setLayout(new BorderLayout()); controlPanel = createControlPanel(); add(controlPanel, BorderLayout.NORTH); //<snip>Create JTable oscarTable = new JTable(oscarModel); //</snip> //</snip>Set JTable display properties oscarTable.setColumnModel(createColumnModel()); oscarTable.setAutoCreateRowSorter(true); oscarTable.setRowHeight(26); oscarTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); oscarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); oscarTable.setIntercellSpacing(new Dimension(0, 0)); //</snip> //<snip>Initialize preferred size for table's viewable area Dimension viewSize = new Dimension(); viewSize.width = oscarTable.getColumnModel().getTotalColumnWidth(); viewSize.height = 10 * oscarTable.getRowHeight(); oscarTable.setPreferredScrollableViewportSize(viewSize); //</snip> //<snip>Customize height and alignment of table header JTableHeader header = oscarTable.getTableHeader(); header.setPreferredSize(new Dimension(30, 26)); TableCellRenderer headerRenderer = header.getDefaultRenderer(); if (headerRenderer instanceof JLabel) { ((JLabel) headerRenderer).setHorizontalAlignment(JLabel.CENTER); } //</snip> LuckScrollPane scrollpane = new LuckScrollPane(oscarTable); dataPanel = new Stacker(scrollpane); add(dataPanel, BorderLayout.CENTER); add(createStatusBar(), BorderLayout.SOUTH); }
Example 12
Source File: TableDemo.java From beautyeye with Apache License 2.0 | 4 votes |
protected void initComponents() { setLayout(new BorderLayout()); controlPanel = createControlPanel(); add(controlPanel, BorderLayout.NORTH); // <snip>Create JTable oscarTable = new JTable(oscarModel); // </snip> // </snip>Set JTable display properties oscarTable.setColumnModel(createColumnModel()); oscarTable.setAutoCreateRowSorter(true); oscarTable.setRowHeight(26); oscarTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); oscarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); oscarTable.setIntercellSpacing(new Dimension(0, 0)); // </snip> // <snip>Initialize preferred size for table's viewable area Dimension viewSize = new Dimension(); viewSize.width = oscarTable.getColumnModel().getTotalColumnWidth(); viewSize.height = 10 * oscarTable.getRowHeight(); oscarTable.setPreferredScrollableViewportSize(viewSize); // </snip> // <snip>Customize height and alignment of table header JTableHeader header = oscarTable.getTableHeader(); header.setPreferredSize(new Dimension(30, 26)); TableCellRenderer headerRenderer = header.getDefaultRenderer(); if (headerRenderer instanceof JLabel) { ((JLabel) headerRenderer).setHorizontalAlignment(JLabel.CENTER); } // </snip> JScrollPane scrollpane = new JScrollPane(oscarTable); dataPanel = new Stacker(scrollpane); add(dataPanel, BorderLayout.CENTER); add(createStatusBar(), BorderLayout.SOUTH); }
Example 13
Source File: JTableLogs.java From mts with GNU General Public License v3.0 | 4 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JTextArea jTextArea = super.getJTextArea(isSelected); TextEvent textEvent = (TextEvent) table.getModel().getValueAt(row, column); if (null == value) { jTextArea.setText(""); jTextArea.setBackground(Color.WHITE); jTextArea.setForeground(Color.BLACK); } else { String text = textEvent.getText(); jTextArea.setText(text); jTextArea.setBackground(GuiHelper.getColorForTopic(textEvent.getTopic())); jTextArea.setForeground(GuiHelper.getColorForLevel(textEvent.getLevel())); jTextArea.setMinimumSize(new Dimension(table.getRowHeight(), table.getRowHeight())); // to get the prefered height jTextArea.setSize(table.getColumnModel().getColumn(column).getWidth(), -1); jTextArea.setSize(table.getColumnModel().getColumn(column).getWidth(), (int) jTextArea.getPreferredSize().getHeight()); int preferedHeight = (int) Math.round(jTextArea.getPreferredSize().getHeight()); // set the prefered height if is different if (table.getRowHeight(row) != preferedHeight && table.getRowHeight(row) != table.getRowHeight()) { table.setRowHeight(row, preferedHeight); } if (search != null) { if (text.toLowerCase().contains(search)) { jTextArea.setBackground(Color.ORANGE); jTextArea.setForeground(Color.BLACK); } } if ((row == index) && (index > -1)) { jTextArea.setBackground(Color.YELLOW); jTextArea.setForeground(Color.BLACK); // table.setRowHeight(row, (int) jTextArea.getPreferredSize().getHeight()); } } if (table.getRowHeight(row) != table.getRowHeight()) { jTextArea.setToolTipText("Click to collapse"); } return jTextArea; }
Example 14
Source File: MapRuleRender.java From xtunnel with GNU General Public License v2.0 | 4 votes |
void update(MapRule rule,JTable table,int row){ this.rule=rule; StringBuffer sb1=new StringBuffer(); StringBuffer sb=new StringBuffer(); MapServerBean mp=rule.getMapserver(); //mp.setDomainName("mhbz.net"); int rowHeight=50; int type=rule.getType(); int h=table.getRowHeight(row); if(h!=rowHeight){ table.setRowHeight(row, rowHeight); } String name=rule.getName(); if(name==null){ name="无"; }else if(name.trim().equals("")){ name="无"; } // String status="离线"; MapMonit client=PMClientUI.get().getControlClient().getMapMonit(); if(client!=null){ if(client.isOnline()){ status="在线"; } } sb1.append("名称:"+name+" "); sb1.append("类型:"+rule.getTypeString()+" 状态:"+status); label1.setText(sb1.toString()); String wanAddress=rule.getWanAddress(); if(type==MapRule.type_single_port){ if(rule.getMapserver().getDomainName()==null){ wanAddress=pui.getConfig().getServerAddress()+":"+rule.getPort(); } } sb.append("外网地址:"+wanAddress+" 内网地址:"+rule.getLanAddress()+ (rule.getCustomAddress()!=null?(" 自定义地址:"+rule.getCustomAddress()):"")); label_wan_address.setText(sb.toString()); }
Example 15
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 4 votes |
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int)Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize(); width = Math.max((int)headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize(); int newHeight = (int)(dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
Example 16
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 4 votes |
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); //table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
Example 17
Source File: DateTimeTableEditor.java From LGoodDatePicker with MIT License | 3 votes |
/** * zAdjustTableRowHeightIfNeeded, If needed, this will adjust the row height for all rows in the * supplied table to fit the minimum row height that is needed to display the DateTimePicker * component. * * If autoAdjustMinimumTableRowHeight is false, this will do nothing. If the row height of the * table is already greater than or equal to "minimumRowHeightInPixels", then this will do * nothing. */ private void zAdjustTableRowHeightIfNeeded(JTable table) { if (!autoAdjustMinimumTableRowHeight) { return; } if ((table.getRowHeight() < minimumRowHeightInPixels)) { table.setRowHeight(minimumRowHeightInPixels); } }
Example 18
Source File: DateTableEditor.java From LGoodDatePicker with MIT License | 3 votes |
/** * zAdjustTableRowHeightIfNeeded, If needed, this will adjust the row height for all rows in the * supplied table to fit the minimum row height that is needed to display the date picker * component. * * If autoAdjustMinimumTableRowHeight is false, this will do nothing. If the row height of the * table is already greater than or equal to "minimumRowHeightInPixels", then this will do * nothing. */ private void zAdjustTableRowHeightIfNeeded(JTable table) { if (!autoAdjustMinimumTableRowHeight) { return; } if ((table.getRowHeight() < minimumRowHeightInPixels)) { table.setRowHeight(minimumRowHeightInPixels); } }
Example 19
Source File: TimeTableEditor.java From LGoodDatePicker with MIT License | 3 votes |
/** * zAdjustTableRowHeightIfNeeded, If needed, this will adjust the row height for all rows in the * supplied table to fit the minimum row height that is needed to display the time picker * component. * * If autoAdjustMinimumTableRowHeight is false, this will do nothing. If the row height of the * table is already greater than or equal to "minimumRowHeightInPixels", then this will do * nothing. */ private void zAdjustTableRowHeightIfNeeded(JTable table) { if (!autoAdjustMinimumTableRowHeight) { return; } if ((table.getRowHeight() < minimumRowHeightInPixels)) { table.setRowHeight(minimumRowHeightInPixels); } }
Example 20
Source File: MDefaultTableCellRenderer.java From javamelody with Apache License 2.0 | 3 votes |
/** * Ajustement de la hauteur de cette ligne en fonction de la taille du renderer (ex: la taille d'une icône ou d'un label html). * * @param table * JTable * @param component * Component * @param row * int */ protected void adjustRowHeight(final JTable table, final Component component, final int row) { // Ajustement de la hauteur de cette ligne en fonction de la taille du renderer final int cellHeight = table.getRowHeight(row); final int rendererHeight = component.getPreferredSize().height; if (cellHeight < rendererHeight - 4) { // dans le cas normal, cellHeight est à 16 et rendererHeight est à 20 table.setRowHeight(row, rendererHeight); } }