List of usage examples for javax.swing.table TableColumn setMaxWidth
@BeanProperty(description = "The maximum width of the column.") public void setMaxWidth(int maxWidth)
TableColumn
's maximum width to maxWidth
or, if maxWidth
is less than the minimum width, to the minimum width. From source file:org.openflexo.technologyadapter.excel.view.ExcelSheetView.java
public ExcelSheetView(ExcelSheet sheet, FlexoController controller) { super(new BorderLayout()); this.sheet = sheet; this.controller = controller; tableModel = new ExcelSheetTableModel(); table = new MultiSpanCellTable(tableModel); table.setBackground(Color.WHITE); table.setShowGrid(true);// w w w . j a v a 2 s . com table.setGridColor(Color.LIGHT_GRAY); table.setRowMargin(0); table.getColumnModel().setColumnMargin(0); for (int i = 0; i < tableModel.getColumnCount(); i++) { TableColumn col = table.getColumnModel().getColumn(i); if (i == 0) { col.setWidth(25); col.setPreferredWidth(25); col.setMinWidth(25); col.setMaxWidth(100); // col.setResizable(false); col.setHeaderValue(null); } else { col.setWidth(sheet.getSheet().getColumnWidth(i - 1) / 40); col.setPreferredWidth(sheet.getSheet().getColumnWidth(i - 1) / 40); col.setHeaderValue("" + Character.toChars(i + 64)[0]); } } table.setDefaultRenderer(Object.class, new ExcelSheetCellRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); add(new JScrollPane(table), BorderLayout.CENTER); cellIdentifier = new JTextField(6); cellIdentifier.setEditable(false); cellIdentifier.setHorizontalAlignment(SwingConstants.CENTER); cellValue = new JTextField(); cellValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { valueEditedForSelectedCell(cellValue.getText()); } }); /*cellValue.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } @Override public void insertUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } @Override public void changedUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } });*/ JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(cellIdentifier, BorderLayout.WEST); topPanel.add(cellValue, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { selectionChanged(); } }); table.getColumnModel().addColumnModelListener(new TableColumnModelListener() { @Override public void columnSelectionChanged(ListSelectionEvent e) { selectionChanged(); } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { } @Override public void columnMarginChanged(ChangeEvent e) { } @Override public void columnAdded(TableColumnModelEvent e) { } }); updateRowHeights(); validate(); /*for (Object p : sheet.getSheet().getWorkbook().getAllPictures()) { System.out.println("Picture: " + p); } System.out.println("class = " + sheet.getSheet().getClass()); if (sheet.getSheet() instanceof HSSFSheet) { List<HSSFShape> shapes = ((HSSFSheet) sheet.getSheet()).getDrawingPatriarch().getChildren(); System.out.println("Prout=" + shapes); for (int i = 0; i < shapes.size(); i++) { System.out.println("hop avec " + shapes.get(i)); if (shapes.get(i) instanceof HSSFPicture) { HSSFPicture pic = (HSSFPicture) shapes.get(i); HSSFPictureData picdata = ((HSSFSheet) sheet.getSheet()).getWorkbook().getAllPictures().get(pic.getPictureIndex()); System.out.println("New picture found : " + pic); System.out.println("Anchor : " + pic.getAnchor()); System.out.println("file extension " + picdata.suggestFileExtension()); // int pictureIndex = this.newSheet.getWorkbook().addPicture( picdata.getData(), picdata.getFormat()); // this.newSheet.createDrawingPatriarch().createPicture((HSSFClientAnchor)pic.getAnchor()r, pictureIndex); } } }*/ }
From source file:org.pentaho.reporting.ui.datasources.table.TableEditor.java
public void addColumn(final TableColumn column) { stopEditing();/*w ww. j a v a2 s . c o m*/ if (column.getHeaderValue() == null) { final int modelColumn = column.getModelIndex(); final String columnName = getModel().getColumnName(modelColumn); if (modelColumn == 0) { column.setResizable(false); column.setHeaderValue(columnName); column.setPreferredWidth(30); column.setMaxWidth(30); column.setMinWidth(30); } else { final Class columnType = getModel().getColumnClass(modelColumn); column.setHeaderValue(new TypedHeaderInformation(columnType, columnName)); } } getColumnModel().addColumn(column); }
From source file:org.piraso.ui.api.StackTraceFilterDialog.java
private void initTable() { TableColumn regexColumn = jtable.getColumnModel().getColumn(0); TableColumn boldColumn = jtable.getColumnModel().getColumn(1); regexColumn.setHeaderValue("Regex"); regexColumn.setPreferredWidth(210);/*w w w . j ava 2s . co m*/ boldColumn.setHeaderValue("Bold"); boldColumn.setPreferredWidth(30); boldColumn.setMaxWidth(30); boldColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class)); boldColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class)); jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.base.ContextMonitorTopComponent.java
private void initColumns() { TableColumn numColumn = table.getColumnModel().getColumn(0); TableColumn messageColumn;// w ww . j a va2s .c om TableColumn elapseColumn; numColumn.setHeaderValue(""); numColumn.setMaxWidth(43); numColumn.setCellRenderer(CELL_RENDERER); showType = SingleModelManagers.GENERAL_SETTINGS.get().isShowType(); if (showType) { TableColumn typeColumn = table.getColumnModel().getColumn(1); messageColumn = table.getColumnModel().getColumn(2); typeColumn.setHeaderValue("Type"); typeColumn.setMaxWidth(125); typeColumn.setCellRenderer(CELL_RENDERER); } else { messageColumn = table.getColumnModel().getColumn(1); } showElapseTime = SingleModelManagers.GENERAL_SETTINGS.get().isShowElapseTime(); if (showElapseTime) { if (showType) { elapseColumn = table.getColumnModel().getColumn(3); } else { elapseColumn = table.getColumnModel().getColumn(2); } elapseColumn.setHeaderValue("Elapse"); elapseColumn.setMaxWidth(100); elapseColumn.setCellRenderer(CELL_RENDERER); } messageColumn.setHeaderValue("Message"); messageColumn.setPreferredWidth(700); messageColumn.setCellRenderer(CELL_RENDERER); }
From source file:org.piraso.ui.base.ExportDialog.java
private void initTable() { TableColumn selectionColumn = jtable.getColumnModel().getColumn(0); TableColumn boldOption = jtable.getColumnModel().getColumn(1); selectionColumn.setHeaderValue(""); selectionColumn.setPreferredWidth(30); selectionColumn.setMaxWidth(30); selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class)); selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class)); boldOption.setHeaderValue("Option"); boldOption.setPreferredWidth(200);/*w w w . j a v a2s . co m*/ jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.base.ProfilesDialog.java
private void initTable() { TableColumn nameColumn = jtable.getColumnModel().getColumn(0); TableColumn urlColumn = jtable.getColumnModel().getColumn(1); TableColumn watchColumn = jtable.getColumnModel().getColumn(2); nameColumn.setHeaderValue("Name"); urlColumn.setPreferredWidth(210);/* w w w .j av a2 s . c o m*/ nameColumn.setMaxWidth(235); urlColumn.setHeaderValue("Logging URL"); urlColumn.setPreferredWidth(220); urlColumn.setMaxWidth(700); watchColumn.setHeaderValue("Watch Address"); watchColumn.setMaxWidth(200); jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.base.SaveMonitorInstanceDialog.java
private void initTable() { TableColumn selectionColumn = jtable.getColumnModel().getColumn(0); TableColumn boldOption = jtable.getColumnModel().getColumn(1); selectionColumn.setHeaderValue(""); selectionColumn.setPreferredWidth(30); selectionColumn.setMaxWidth(30); selectionColumn.setCellEditor(jtable.getDefaultEditor(Boolean.class)); selectionColumn.setCellRenderer(jtable.getDefaultRenderer(Boolean.class)); boldOption.setHeaderValue("Request URL"); boldOption.setPreferredWidth(200);//from w w w . j a v a 2 s . c o m jtable.setShowHorizontalLines(false); jtable.setAutoscrolls(true); jtable.setColumnSelectionAllowed(false); jtable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtable.getTableHeader().setReorderingAllowed(false); }
From source file:org.piraso.ui.sql.SQLViewTopComponent.java
private void initTable() { TableColumn numColumn = table.getColumnModel().getColumn(0); TableColumn methodColumn = table.getColumnModel().getColumn(1); TableColumn typeColumn = table.getColumnModel().getColumn(2); TableColumn valueColumn = table.getColumnModel().getColumn(3); numColumn.setHeaderValue(""); numColumn.setMaxWidth(30); numColumn.setCellRenderer(new AlignableTableCellRendererImpl(SwingConstants.RIGHT, false, true)); methodColumn.setHeaderValue("Method"); methodColumn.setPreferredWidth(300); typeColumn.setHeaderValue("Type"); typeColumn.setPreferredWidth(200);/*from w w w . java2s. co m*/ valueColumn.setHeaderValue("Value"); valueColumn.setPreferredWidth(200); }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void makeTableColumnWidthFit(JTable jTable, int col, int margin, boolean locking) { // strategy - get max width for cells in column and // make that the preferred width TableColumnModel columnModel = jTable.getColumnModel(); int maxwidth = 0; for (int row = 0; row < jTable.getRowCount(); row++) { TableCellRenderer rend = jTable.getCellRenderer(row, col); Object value = jTable.getValueAt(row, col); Component comp = rend.getTableCellRendererComponent(jTable, value, false, false, row, col); maxwidth = Math.max(comp.getPreferredSize().width + margin, maxwidth); } // for row// ww w.j av a 2 s .co m TableColumn column = columnModel.getColumn(col); TableCellRenderer headerRenderer = column.getHeaderRenderer(); if (headerRenderer == null) { headerRenderer = jTable.getTableHeader().getDefaultRenderer(); } Object headerValue = column.getHeaderValue(); Component headerComp = headerRenderer.getTableCellRendererComponent(jTable, headerValue, false, false, 0, col); maxwidth = Math.max(maxwidth, headerComp.getPreferredSize().width + margin); column.setPreferredWidth(maxwidth); if (locking) { // User will not able to adjust the width manually. column.setMinWidth(maxwidth); column.setMaxWidth(maxwidth); } }
From source file:org.zaproxy.zap.extension.httppanel.view.paramtable.HttpPanelParamTableView.java
private void init() { // Table/* w ww . java2 s . c om*/ table = new JTable(); table.setName(""); table.setModel(httpPanelTabularModel); table.setGridColor(java.awt.Color.gray); table.setIntercellSpacing(new java.awt.Dimension(1, 1)); table.setRowHeight(DisplayUtils.getScaledSize(18)); // Issue 954: Force the JTable cell to auto-save when the focus changes. // Example, edit cell, click OK for a panel dialog box, the data will get saved. table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // Set standard row width's TableColumn column = table.getColumnModel().getColumn(0); column.setPreferredWidth(70); column.setWidth(70); column.setMaxWidth(70); if (table.getColumnCount() == 4) { column = table.getColumnModel().getColumn(3); column.setPreferredWidth(150); column.setWidth(150); column.setMaxWidth(150); } // Main panel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(new JScrollPane(table), BorderLayout.CENTER); }