List of usage examples for javax.swing.table TableColumn setPreferredWidth
@BeanProperty(description = "The preferred width of the column.") public void setPreferredWidth(int preferredWidth)
preferredWidth
. From source file:org.kepler.gui.ComponentLibraryPreferencesTab.java
/** * Initialize the source list table.// ww w . j a va2s.c o m */ private void initSourceList() { try { ComponentSourceTableModel cstm = new ComponentSourceTableModel(); _sourceList = new JTable(cstm); _sourceList.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); _sourceList.setShowGrid(true); _sourceList.setShowHorizontalLines(true); _sourceList.setShowVerticalLines(true); _sourceList.setGridColor(Color.lightGray); _sourceList.setIntercellSpacing(new Dimension(5, 5)); _sourceList.setRowHeight(_sourceList.getRowHeight() + 10); _sourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (isDebugging) { log.debug("intercellspacing: " + _sourceList.getIntercellSpacing().toString()); log.debug("getRowHeight(): " + _sourceList.getRowHeight()); } // Search column TableColumn c0 = _sourceList.getColumnModel().getColumn(0); c0.setMinWidth(50); c0.setPreferredWidth(60); c0.setMaxWidth(100); c0.setResizable(true); // Save column TableColumn c1 = _sourceList.getColumnModel().getColumn(1); c1.setMinWidth(50); c1.setPreferredWidth(60); c1.setMaxWidth(100); c1.setResizable(true); // Type column TableColumn c2 = _sourceList.getColumnModel().getColumn(2); c2.setMinWidth(50); c2.setPreferredWidth(60); c2.setMaxWidth(100); c2.setResizable(true); // Name column TableColumn c3 = _sourceList.getColumnModel().getColumn(3); c3.setMinWidth(50); c3.setPreferredWidth(100); c3.setMaxWidth(200); c3.setResizable(true); // Source column TableColumn c4 = _sourceList.getColumnModel().getColumn(4); c4.setMinWidth(200); c4.setPreferredWidth(600); c4.setMaxWidth(2000); c4.setResizable(true); JScrollPane sourceListSP = new JScrollPane(_sourceList); sourceListSP.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); sourceListSP.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); sourceListSP.setBackground(TabManager.BGCOLOR); add(sourceListSP); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:org.lockss.devtools.plugindef.EDPInspectorTableModel.java
public void setColumnSize(JTable table, int col) { TableColumn column = null; Component comp = null;/*from w ww . j av a 2 s . c om*/ int headerWidth = 0; int cellWidth = 0; String longestStr = ""; String curString = ""; for (int row = 0; row < inspectorEntries.length; row++) { curString = data[row][col].toString(); if (curString.length() > longestStr.length()) { longestStr = curString; } } TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); column = table.getColumnModel().getColumn(col); comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; comp = table.getDefaultRenderer(getColumnClass(col)).getTableCellRendererComponent(table, longestStr, false, false, 0, col); cellWidth = comp.getPreferredSize().width; column.setPreferredWidth(Math.max(headerWidth, cellWidth)); }
From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java
private void setColumnWidth(TableColumn column, int initial, int max, int min) { if (initial != 0) { column.setPreferredWidth(initial); }//from ww w .j a v a2 s.c o m if (max != 0) { column.setMaxWidth(max); } if (min != 0) { column.setMinWidth(min); } }
From source file:org.nuclos.client.ui.collect.SubForm.java
/** * sets all column widths to user preferences; set optimal width if no preferences yet saved * @param tableColumnWidthsFromPreferences */// www . j a v a2 s .c o m public final void setColumnWidths(List<Integer> tableColumnWidthsFromPreferences) { useCustomColumnWidths = !tableColumnWidthsFromPreferences.isEmpty() && tableColumnWidthsFromPreferences.size() <= subformtbl.getColumnCount(); if (useCustomColumnWidths) { assert (tableColumnWidthsFromPreferences.size() <= subformtbl.getColumnCount()); final Enumeration<TableColumn> enumeration = subformtbl.getColumnModel().getColumns(); int iColumn = 0; while (enumeration.hasMoreElements()) { final TableColumn column = enumeration.nextElement(); final int iPreferredCellWidth; if (iColumn < tableColumnWidthsFromPreferences.size()) { // known column iPreferredCellWidth = tableColumnWidthsFromPreferences.get(iColumn++); } else { // new column iPreferredCellWidth = getDefaultColumnWidth(column, iColumn++); } column.setPreferredWidth(iPreferredCellWidth); column.setWidth(iPreferredCellWidth); } } else { resetDefaultColumnWidths(); } }
From source file:org.nuclos.client.ui.collect.SubForm.java
public final void resetDefaultColumnWidths() { if (subformtbl != null) { for (int iColumn = 0; iColumn < subformtbl.getColumnCount(); iColumn++) { final TableColumn tableColumn = subformtbl.getColumnModel().getColumn(iColumn); final int width = getDefaultColumnWidth(tableColumn, iColumn); tableColumn.setPreferredWidth(width); tableColumn.setWidth(width); }/*w ww . j a v a2 s . co m*/ useCustomColumnWidths = false; subformtbl.revalidate(); } }
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 va 2 s . c o m*/ 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();//from w w w . jav 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); boldColumn.setHeaderValue("Bold"); boldColumn.setPreferredWidth(30);// w w w. ja v a 2s . c o m 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.api.WorkingSetDialog.java
private void initTable() { TableColumn regexColumn = jtable.getColumnModel().getColumn(0); TableColumn boldColumn = jtable.getColumnModel().getColumn(1); regexColumn.setHeaderValue("Name"); regexColumn.setPreferredWidth(210); boldColumn.setHeaderValue("Regex"); boldColumn.setPreferredWidth(210);//from w ww . j a v a 2s . 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.ContextMonitorTopComponent.java
private void initColumns() { TableColumn numColumn = table.getColumnModel().getColumn(0); TableColumn messageColumn; TableColumn elapseColumn;/*from www. ja v a2 s .c om*/ 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); }