/** * カラムの非表示設定を行う. * * @param col 対象カラム番号 * @param hide true:表示 false:非表示 */ public void setColumnHide(int col, boolean hide) { TableColumn tc = getColumnModel().getColumn(convertColumnIndexToView(col)); int[] setting = new int[4]; setting[0] = tc.getWidth(); setting[1] = tc.getPreferredWidth(); setting[2] = tc.getMinWidth(); setting[3] = tc.getMaxWidth(); if (hide) { if ((setting[0] == 0) && (setting[1] == 0) && (setting[2] == 0) && (setting[3] == 0)) { int[] baseSetting = columnSizeSetting.get(col); // setMaxWidthを実行する順番が大事 tc.setMaxWidth(baseSetting[3]); tc.setMinWidth(baseSetting[2]); tc.setPreferredWidth(baseSetting[1]); tc.setWidth(baseSetting[0]); } } else { if ((setting[0] != 0) || (setting[1] != 0) || (setting[2] != 0) || (setting[3] != 0)) { columnSizeSetting.put(col, setting); // setMaxWidthを実行する順番が大事 tc.setWidth(0); tc.setPreferredWidth(0); tc.setMinWidth(0); tc.setMaxWidth(0); } } }
private void setColumnWidths() { if (!initialised) { return; } TableColumn checkCol = getColumnModel().getColumn(0); TableColumn descCol = getColumnModel().getColumn(1); TableColumn actCol = getColumnModel().getColumn(2); checkCol.setMinWidth(35); checkCol.setMaxWidth(35); checkCol.setWidth(30); int descWidth = getFontMetrics(getFont()).stringWidth(DESC_WIDTH_TEXT); descCol.setMinWidth(descWidth); descCol.setWidth(descWidth); // no maximum set, so it will stretch... actCol.setMinWidth(50); actCol.setMaxWidth(55); actCol.setWidth(55); /* and for advanced mode: */ if (getColumnModel().getColumnCount() > 3) { descCol.setMinWidth(descWidth / 2); TableColumn prioCol = getColumnModel().getColumn(3); prioCol.setMinWidth(45); prioCol.setMaxWidth(50); prioCol.setWidth(50); } }
/** Ustawienie atrybutów tabeli (np. szerokość kolumn). */ private void initTableModel() { int cols = model.getColumnCount(); TableColumn col; col = table.getColumnModel().getColumn(0); col.setPreferredWidth(60); col.setMaxWidth(60); col = table.getColumnModel().getColumn(1); col.setPreferredWidth(150); col.setMaxWidth(400); col = table.getColumnModel().getColumn(2); col.setPreferredWidth(200); col.setMaxWidth(1000); for (int i = 3; i < cols - 1; i++) { col = table.getColumnModel().getColumn(i); col.setPreferredWidth(60); col.setMaxWidth(100); } col = table.getColumnModel().getColumn(cols - 1); col.setPreferredWidth(60); col.setMaxWidth(100); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(SwingConstants.RIGHT); // wyrównanie do prawej kolumny oceny col.setCellRenderer(r); table.setRowSelectionInterval(0, 0); }
private void iniciarTabela() { tblCliente.setAutoCreateRowSorter(true); tblCliente.setRowHeight(35); TableColumn colunaDoc = tblCliente.getColumnModel().getColumn(DOCUMENTO); TableColumn colunaNome = tblCliente.getColumnModel().getColumn(NOME); TableColumn colunaEnd = tblCliente.getColumnModel().getColumn(ENDERECO); TableColumn colunaTel = tblCliente.getColumnModel().getColumn(TELEFONE); TableColumn colunaEdit = tblCliente.getColumnModel().getColumn(EDITAR); TableColumn colunaExcl = tblCliente.getColumnModel().getColumn(EXCLUIR); colunaDoc.setPreferredWidth(20); colunaNome.setPreferredWidth(200); colunaEnd.setPreferredWidth(200); colunaTel.setPreferredWidth(20); colunaEdit.setMaxWidth(50); colunaEdit.setMinWidth(35); colunaEdit.setCellRenderer(AbstractTableCrud.getIconCellRenderer()); colunaExcl.setMaxWidth(50); colunaExcl.setMinWidth(35); colunaExcl.setCellRenderer(AbstractTableCrud.getIconCellRenderer()); }
/** Setzt die Breite der Spalten */ public void setTableSize() { // Spaltenbreite der Checkboxen setzen TableColumn tc0 = table.getColumn(prakColumnNames[0]); // EventID TableColumn tc1 = table.getColumn(prakColumnNames[1]); // TutorID TableColumn tc2 = table.getColumn(prakColumnNames[2]); // Checkbox tc0.setMinWidth(0); tc0.setMaxWidth(0); tc1.setMinWidth(0); tc1.setMaxWidth(0); tc2.setMaxWidth(10); tc2.setMinWidth(10); }
public void updateColumnSizes() { final JTableHeader header = getTableHeader(); final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer(); final RowSorter<? extends TableModel> sorter = getRowSorter(); final List<? extends RowSorter.SortKey> current = sorter == null ? null : sorter.getSortKeys(); ColumnInfo[] columns = getListTableModel().getColumnInfos(); for (int i = 0; i < columns.length; i++) { final ColumnInfo columnInfo = columns[i]; final TableColumn column = getColumnModel().getColumn(i); // hack to get sort arrow included into the renderer component if (sorter != null && columnInfo.isSortable()) { sorter.setSortKeys( Collections.singletonList(new RowSorter.SortKey(i, SortOrder.ASCENDING))); } final Component headerComponent = defaultRenderer == null ? null : defaultRenderer.getTableCellRendererComponent( this, column.getHeaderValue(), false, false, 0, 0); if (sorter != null && columnInfo.isSortable()) { sorter.setSortKeys(current); } final Dimension headerSize = headerComponent == null ? new Dimension(0, 0) : headerComponent.getPreferredSize(); final String maxStringValue; final String preferredValue; if (columnInfo.getWidth(this) > 0) { int width = columnInfo.getWidth(this); column.setMaxWidth(width); column.setPreferredWidth(width); column.setMinWidth(width); } else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) { int width = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth(); width = Math.max(width, headerSize.width); column.setPreferredWidth(width); column.setMaxWidth(width); } else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) { int width = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth(); width = Math.max(width, headerSize.width); column.setPreferredWidth(width); } } }
private void fnHideColumn() { TableColumnModel tcm = this.tablePanel.getColumnModel(); Object[] selected = this.cbList.getCheckBoxListSelectedValues(); for (int i = 0; i < tcm.getColumnCount(); i++) { TableColumn tc = tcm.getColumn(i); String value = tc.getHeaderValue().toString(); boolean matched = false; for (int j = 0; j < selected.length; j++) { if (value.equalsIgnoreCase(selected[j].toString())) { matched = true; break; } } if (!matched) { tc.setMinWidth(0); tc.setMaxWidth(0); } else { int width = this.model.getColumnWidth(value); tc.setMinWidth(width); tc.setWidth(width); tc.setPreferredWidth(width); } } }
PluginInstallDialog(Studio app, PluginManagerDialog parent) { super(parent); this.app = app; plugins = parent.getInstallablePlugins(); JPanel c = new JPanel(new BorderLayout(10, 10)); c.setBorder(BorderFactory.createEmptyBorder(10, 10, 5, 10)); c.add(new JLabel("Select Plugins to install"), BorderLayout.NORTH); // JPanel p = new JPanel(new GridLayout(1,2,5,5)); table = new JTable(new DataModel()); table.setTableHeader(null); table.setShowGrid(false); TableColumn col = table.getColumn(table.getColumnName(0)); col.setMaxWidth(col.getMinWidth()); table.setPreferredScrollableViewportSize(table.getPreferredSize()); c.add(new JScrollPane(table), BorderLayout.WEST); table.getSelectionModel().addListSelectionListener(this); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); info = new PluginInfoPanel(); info.setBorder(BorderFactory.createTitledBorder("Plugin Info")); c.add(info, BorderLayout.CENTER); // c.add(p,BorderLayout.CENTER); JPanel bottom = new JPanel(new BorderLayout()); JPanel cb = new JPanel(new BorderLayout()); String dir = app.getUserExtensionsDir(); cb1 = new JRadioButton("Install in user directory (" + dir + ")"); File df = new File(dir); if (!df.exists()) df.mkdirs(); cb1.setEnabled(dir != null && df.canWrite()); cb1.setSelected(true); cb.add(cb1, BorderLayout.NORTH); dir = app.getSystemExtensionsDir(); cb2 = new JRadioButton("Install in system directory (" + dir + ")"); df = new File(dir); if (!df.exists()) df.mkdirs(); cb2.setEnabled(dir != null && df.canWrite()); cb.add(cb2, BorderLayout.SOUTH); ButtonGroup rg = new ButtonGroup(); rg.add(cb1); rg.add(cb2); bottom.add(cb, BorderLayout.NORTH); install = new JButton("Install"); install.addActionListener(this); install.setEnabled(false); close = new JButton("Close"); close.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.add(install); buttonPanel.add(close); bottom.add(buttonPanel, BorderLayout.SOUTH); c.add(bottom, BorderLayout.SOUTH); setContentPane(c); }
public void init(TableColumn column) { DateCellRenderer cellRenderer = new DateCellRenderer(getRaplaLocale()); cellRenderer.setSubstractDayWhenFullDay(true); column.setCellRenderer(cellRenderer); column.setMaxWidth(175); column.setPreferredWidth(175); }
private void initComponents() { { DefaultTableColumnModel model = new DefaultTableColumnModel(); TableColumn column = new TableColumn(0); column.setResizable(true); model.addColumn(column); column = new TableColumn(1, 120, new ButtonCellRenderer(), null); column.setMaxWidth(120); column.setResizable(false); model.addColumn(column); companionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); companionsTable.getTableHeader().setResizingAllowed(false); companionsTable.setAutoCreateColumnsFromModel(false); companionsTable.setColumnModel(model); } companionsTable.setIntercellSpacing(new Dimension(0, 0)); companionsTable.setFocusable(false); companionsTable.setRowHeight(23); companionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLeftComponent(new JScrollPane(companionsTable)); JPanel rightPane = new JPanel(new BorderLayout()); infoPane.setOpaque(false); infoPane.setEditable(false); infoPane.setFocusable(true); infoPane.setContentType("text/html"); // $NON-NLS-1$ rightPane.add(new JScrollPane(infoPane), BorderLayout.CENTER); JPanel buttonPane = new JPanel(new FlowLayout()); buttonPane.add(loadButton); rightPane.add(buttonPane, BorderLayout.SOUTH); setRightComponent(rightPane); }
private void setColumnPreferredSize() { for (int i = 0; i < getColumnCount(); i++) { TableColumn column = getColumnModel().getColumn(i); if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0; // NB: all further instructions and their order are important, otherwise the minimum size // which is less than 15 won't be applied column.setMinWidth(rootWidth); column.setMaxWidth(rootWidth); column.setPreferredWidth(rootWidth); } else if (i == AbstractVcsLogTableModel .COMMIT_COLUMN) { // let commit message occupy as much as possible column.setPreferredWidth(Short.MAX_VALUE); } else if (i == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name // to avoid querying the last row (it would lead to full graph loading) int maxRowsToCheck = Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET); if (maxRowsToCheck < 0) { // but if the log is small, check all of them maxRowsToCheck = getRowCount(); } int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck); column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH)); column.setWidth(column.getMinWidth()); } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes Font tableFont = UIManager.getFont("Table.font"); column.setMinWidth( getFontMetrics(tableFont) .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date()))); column.setWidth(column.getMinWidth()); } } }
/** * Creates a new <code>TableColumnModel</code> along with its <code>TableColumn</code>s: * Selection, Name and Value columns. * * @return A new <code>TableColumnModel</code> */ private TableColumnModel buildTableColumnModel() { DefaultTableColumnModel model = new DefaultTableColumnModel(); // Selection column TableColumn selectionColumn = new TableColumn(PropertyColumnAdapter.SELECTION_COLUMN); selectionColumn.setCellRenderer(new SelectionTableCellRenderer()); selectionColumn.setHeaderValue(" "); selectionColumn.setMaxWidth(20); selectionColumn.setMinWidth(20); selectionColumn.setPreferredWidth(20); selectionColumn.setResizable(false); model.addColumn(selectionColumn); // Name column TableColumn nameColumn = new TableColumn(PropertyColumnAdapter.NAME_COLUMN); nameColumn.setHeaderValue(resourceRepository().getString("LOGIN_PROPERTY_NAME_COLUMN")); nameColumn.setMinWidth(50); nameColumn.setResizable(true); model.addColumn(nameColumn); // Value column TableColumn valueColumn = new TableColumn(PropertyColumnAdapter.VALUE_COLUMN); valueColumn.setHeaderValue(resourceRepository().getString("LOGIN_PROPERTY_VALUE_COLUMN")); valueColumn.setMinWidth(50); valueColumn.setResizable(true); model.addColumn(valueColumn); return model; }
private void prepareComponent() { CloseEventHandler closeEventHandler = new CloseEventHandler(); addWindowListener(closeEventHandler); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel contentPanel = new JPanel(); // JPanel contentPanel = new FormDebugPanel(); contentPane.add(contentPanel, BorderLayout.CENTER); CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout( "4dlu, d:grow, 4dlu", // columns "4dlu, p, 2dlu, fill:100dlu:grow, 4dlu, " + // rows "p, 2dlu, p, 4dlu"); // btn rows PanelBuilder contentPB = new PanelBuilder(layout, contentPanel); int columnCount = layout.getColumnCount(); int rowCount = layout.getRowCount(); JLabel label = new JLabel(Localizer.getString("MediaTypeCondEditor_ConditionToAdd")); contentPB.add(label, cc.xywh(2, 2, 1, 1)); mediaTypeModel = new MediaTypeModel(); mediaTypeTable = new JTable(mediaTypeModel); JTableHeader tableHeader = mediaTypeTable.getTableHeader(); tableHeader.setResizingAllowed(false); tableHeader.setReorderingAllowed(false); // adjust column witdh of checkbox JCheckBox box = (JCheckBox) mediaTypeTable.getDefaultRenderer(Boolean.class); TableColumn column = mediaTypeTable.getColumnModel().getColumn(0); column.setMaxWidth(box.getPreferredSize().width + 2); column.setMinWidth(box.getPreferredSize().width + 2); mediaTypeTable.getColumnModel().getColumn(1).setCellRenderer(new MediaTypeCellRenderer()); // ToolTipManager.sharedInstance().registerComponent( mediaTypeTable ); contentPB.add(new JScrollPane(mediaTypeTable), cc.xywh(2, 4, 1, 1)); // button bar contentPB.add(new JSeparator(), cc.xywh(1, rowCount - 3, columnCount, 1)); JButton okBtn = new JButton(Localizer.getString("OK")); okBtn.addActionListener(new OkBtnListener()); okBtn.setDefaultCapable(true); okBtn.setRequestFocusEnabled(true); JButton cancelBtn = new JButton(Localizer.getString("Cancel")); cancelBtn.addActionListener(closeEventHandler); JPanel btnPanel = ButtonBarFactory.buildOKCancelBar(okBtn, cancelBtn); contentPB.add(btnPanel, cc.xywh(2, rowCount - 1, columnCount - 2, 1)); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); getRootPane().setDefaultButton(okBtn); pack(); setLocationRelativeTo(getParent()); }
public void init() { HierarchicalTableModel<P> tableModel = table.getModel(); this.tableColumns.clear(); if (tableModel == null) return; TableColumn column; int c = 0; if (tableModel.hasExpandableItems()) { Image minusImage = table.getStyle().getExpandedImage(); Image plusImage = table.getStyle().getCollapsedImage(); int w = minusImage.getWidth(null); column = new TableColumn(c++, w + 2, new ExpanderColumnCellRenderer(minusImage, plusImage), null); column.setMinWidth(w + 2); column.setMaxWidth(w + 2); column.setHeaderValue(tableModel.getColumnName(0)); column.setResizable(false); addColumn(column); } if (tableModel.getKeyColumnWidth() >= 0) { int kcw = tableModel.getKeyColumnWidth(); column = new TableColumn(c++, kcw, new KeyCellRenderer<P>(), null); column.setMinWidth(kcw); column.setMaxWidth(kcw); column.setResizable(false); column.setHeaderValue(tableModel.getColumnName(1)); addColumn(column); } else { column = new TableColumn(c++, 20000, new KeyCellRenderer<P>(), null); // column = new TableColumn( c++, 20000, null, null ); column.setHeaderValue(tableModel.getColumnName(1)); addColumn(column); } // column = new TableColumn( c++, 20000, new StringKeyValueCellRenderer(), null ); column = new TableColumn(c++, 20000, null, null); column.setHeaderValue(tableModel.getColumnName(2)); addColumn(column); }
private void removeDefaultColumn(Outline o) { TableColumn nodeColumn = o.getColumnModel().getColumn(0); nodeColumn.setHeaderValue(""); nodeColumn.setWidth(1); nodeColumn.setMaxWidth(1); nodeColumn.setMinWidth(1); // o.getColumnModel().removeColumn(nodeColumn); }
/** * Die Spalte verstecken. * * @param iColumnIndex der Index der Spalte * @param iColumnWidth doe absolute Breite der Spalte */ private void setColumnWidthToZero(int iColumnIndex) { TableColumn tc = table.getColumnModel().getColumn(iColumnIndex); tc.setMinWidth(0); tc.setPreferredWidth(0); boolean showIIds = iColumnIndex == 0 && Defaults.getInstance().isShowIIdColumn(); tc.setMaxWidth(showIIds ? Helper.getBreiteInPixel(QueryParameters.FLR_BREITE_M) : 0); tc.setResizable(showIIds); }
public IdentityProviderAuditRecordTable() { super(createTableModel()); TableColumn c = getColumn(RECORD); c.setMaxWidth(0); c.setMinWidth(0); c.setPreferredWidth(0); c.setResizable(false); this.clearTable(); }
/** Initializes the table. */ protected void init() { refreshTimer.setRepeats(false); refreshTimer.setCoalesce(true); setModel(rowModel); setColumnSelectionAllowed(true); setGridColor(Color.blue); setSelectionBackground(LIGHT_BLUE); setSelectionForeground(Color.red); // foreground color for selected cells setColumnModel(new DataTableColumnModel()); setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); setColumnSelectionAllowed(true); rowModel.addTableModelListener( new TableModelListener() { public void tableChanged(TableModelEvent e) { // forward the table model event to property change listeners DataRowTable.this.firePropertyChange("cell", null, e); // $NON-NLS-1$ } }); setDefaultRenderer(Object.class, cellRenderer); getTableHeader().setForeground(Color.blue); // set text color getTableHeader().setReorderingAllowed(true); getTableHeader().setDefaultRenderer(new HeaderRenderer()); setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int width = 24; String name; TableColumn column; if (getColumnCount() > 0) { // set width of column 0 (row index) name = getColumnName(0); column = getColumn(name); column.setMinWidth(width); column.setMaxWidth(2 * width); column.setWidth(width); } // set width of other columns width = 60; for (int i = 1, n = getColumnCount(); i < n; i++) { name = getColumnName(i); column = getColumn(name); column.setMinWidth(width); column.setMaxWidth(3 * width); column.setWidth(width); } }
/** * Constructs a Panel with a line-number, breakpoint, source-text * * @param dataComm the datacomm object for interaction with the ToolBus * @param scriptName the name of the script that is used by the ToolBus * @param source the source of an toolbus file */ public SourceFilePanel(DataComm dataComm, String scriptName, String source) { super(); m_dataComm = dataComm; setLayout(new BorderLayout()); m_scriptName = scriptName; m_sourceModel = new SourceFileTableModel(source); m_sourceCode = new JTable(m_sourceModel); m_sourceCode.setSelectionBackground(SELECTED_ROW_COLOR); m_sourceCode.setSelectionForeground(Color.BLACK); m_sourceCode.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // to set the background color back to default m_sourceCode.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() == MouseEvent.BUTTON1) { m_sourceCode.setSelectionBackground(SELECTED_ROW_COLOR); } } }); m_sourceCode.getModel().addTableModelListener(this); m_sourceCode.setShowGrid(false); m_sourceCode.setColumnSelectionAllowed(false); m_sourceCode.setRowSelectionAllowed(true); m_sourceCode.getColumnModel().getColumn(0).setCellRenderer(new CheckBoxCellRenderer()); m_sourceCode.getColumnModel().getColumn(0).setCellEditor(new CheckBoxCellRenderer()); TableColumn firstColumn = m_sourceCode.getColumnModel().getColumn(FIRST_COLUMN_INDEX); firstColumn.setMaxWidth(FIRST_COLUMN_WIDTH); TableColumn secondColumn = m_sourceCode.getColumnModel().getColumn(SECOND_COLUMN_INDEX); DefaultTableCellRenderer tcrColumn = new DefaultTableCellRenderer(); tcrColumn.setHorizontalAlignment(SwingConstants.LEFT); secondColumn.setCellRenderer(tcrColumn); secondColumn.setMaxWidth(SECOND_COLUMN_WIDTH); JScrollPane sourceScrollPane = new JScrollPane(m_sourceCode); sourceScrollPane.getViewport().setBackground(Color.WHITE); add(sourceScrollPane, BorderLayout.CENTER); setVisible(true); }
public static void setColumnWidth( JTable table, int columnIndex, int preferredWidth, int maxWidth, int minWidth) { TableColumn column = getTableColumn(table, columnIndex); if (column == null) { return; } column.setPreferredWidth(preferredWidth); column.setMaxWidth(maxWidth); column.setMinWidth(minWidth); }
/** Refresh the cell widths in the table. */ public void refreshCellWidths() { // set width of columns for (int i = 0; i < getColumnCount(); i++) { String name = getColumnName(i); TableColumn statColumn = getColumn(name); name = dataTable.getColumnName(i); TableColumn dataColumn = dataTable.getColumn(name); statColumn.setMaxWidth(dataColumn.getWidth()); statColumn.setMinWidth(dataColumn.getWidth()); statColumn.setWidth(dataColumn.getWidth()); } }
private void setColumnWidth(int num, int minWidth, int maxWidth, int prefWidth) { TableColumn colum = compareTable.getColumnModel().getColumn(num); if (minWidth > 0) { colum.setMinWidth(minWidth); } if (maxWidth > 0) { colum.setMaxWidth(maxWidth); } if (prefWidth > 0) { colum.setPreferredWidth(prefWidth); } }
/** * Resizes the <code>TableColumn</code> to fit the width of its header cell. This method does * nothing if the header renderer is <code>null</code> (the default case). Otherwise, it sets the * minimum, maximum and preferred widths of this column to the widths of the minimum, maximum and * preferred sizes of the Component delivered by the header renderer. The transient "width" * property of this TableColumn is also set to the preferred width. Note this method is not used * internally by the table package. * * @see #setPreferredWidth */ public void sizeWidthToFit() { if (headerRenderer == null) { return; } Component c = headerRenderer.getTableCellRendererComponent(null, getHeaderValue(), false, false, 0, 0); setMinWidth(c.getMinimumSize().width); setMaxWidth(c.getMaximumSize().width); setPreferredWidth(c.getPreferredSize().width); setWidth(getPreferredWidth()); }
public static void loadPlayList(final String fileLocation) { try { System.out.println(fileLocation); table = TabelPanel.table; DefaultTableModel tableModel = TabelPanel.tableModel; final String datafile = fileLocation; final FileReader fin = new FileReader(datafile); tableModel = Csv2TableModel.createTableModel(fin, null); if (tableModel == null) { JOptionPane.showMessageDialog( null, "Error loading playlist, corrupted or unfinished.", "Error", JOptionPane.ERROR_MESSAGE); ModelUtils.loadPlayList("ta/scripts/blank.plist"); PlayListPanel.canSetLast = false; return; } else { PlayListPanel.canSetLast = true; } table.setModel(tableModel); final TableColumn hiddenLink = table.getColumnModel().getColumn(LINK_INDEX); hiddenLink.setMinWidth(2); hiddenLink.setPreferredWidth(2); hiddenLink.setMaxWidth(2); hiddenLink.setCellRenderer(new InteractiveRenderer(LINK_INDEX)); final TableColumn hiddenAlbumArt = table.getColumnModel().getColumn(ALBUMART_INDEX); hiddenAlbumArt.setMinWidth(2); hiddenAlbumArt.setPreferredWidth(2); hiddenAlbumArt.setMaxWidth(2); hiddenAlbumArt.setCellRenderer(new InteractiveRenderer(ALBUMART_INDEX)); } catch (final FileNotFoundException e) { System.out.println("afaafvava"); ModelUtils.loadPlayList("data/scripts/blank.plist"); } }
private void init() { getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setShowGrid(false); setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); TableColumn column = getColumnModel().getColumn(0); int checkBoxWidth = new JCheckBox().getPreferredSize().width; column.setPreferredWidth(checkBoxWidth); column.setMinWidth(checkBoxWidth); column.setWidth(checkBoxWidth); column.setMaxWidth(checkBoxWidth); column.setResizable(false); setTableHeader(null); }
public void updateColumnSizes() { final JTableHeader header = getTableHeader(); final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer(); ColumnInfo[] columns = getListTableModel().getColumnInfos(); for (int i = 0; i < columns.length; i++) { final ColumnInfo columnInfo = columns[i]; final TableColumn column = getColumnModel().getColumn(i); final Component headerComponent = defaultRenderer == null ? null : defaultRenderer.getTableCellRendererComponent( this, column.getHeaderValue(), false, false, 0, 0); final Dimension headerSize = headerComponent == null ? new Dimension(0, 0) : headerComponent.getPreferredSize(); final String maxStringValue; final String preferredValue; if (columnInfo.getWidth(this) > 0) { int width = columnInfo.getWidth(this); column.setMaxWidth(width); column.setPreferredWidth(width); column.setMinWidth(width); } else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) { int width = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth(); width = Math.max(width, headerSize.width); column.setPreferredWidth(width); column.setMaxWidth(width); } else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) { int width = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth(); width = Math.max(width, headerSize.width); column.setPreferredWidth(width); } } }
private void crearTabla() { Tabla tabla = new Tabla(); tabla.agregarColumna(new Columna("CODIGO", "java.lang.Integer")); tabla.agregarColumna(new Columna("NOMBRE", "java.lang.String")); tabla.agregarColumna(new Columna("APELLIDOS", "java.lang.String")); tabla.agregarColumna(new Columna("DNI", "java.lang.String")); tabla.agregarColumna(new Columna("GENERO", "java.lang.String")); tabla.agregarColumna(new Columna("FECHA DE NACIMIENTO", "java.sql.Date")); tabla.agregarColumna(new Columna("TELEFONO", "java.lang.String")); tabla.agregarColumna(new Columna("CORREO", "java.lang.String")); ModeloTabla modeloTablaBibliotecario = new ModeloTabla(tabla); tablaBibliotecario.setModel(modeloTablaBibliotecario); TableColumn columna0, columna1, columna2, columna3, columna4, columna5, columna6, columna7; // CODIGO columna0 = tablaBibliotecario.getColumnModel().getColumn(0); tablaBibliotecario.removeColumn(columna0); // NOMBRE columna1 = tablaBibliotecario.getColumnModel().getColumn(0); columna1.setPreferredWidth(216); columna1.setMaxWidth(216); columna1.setMinWidth(216); // APELLIDOS columna2 = tablaBibliotecario.getColumnModel().getColumn(1); columna2.setPreferredWidth(216); columna2.setMaxWidth(216); columna2.setMinWidth(216); // DNI columna3 = tablaBibliotecario.getColumnModel().getColumn(2); columna3.setPreferredWidth(70); columna3.setMaxWidth(70); columna3.setMinWidth(70); // GENERO columna4 = tablaBibliotecario.getColumnModel().getColumn(3); columna4.setPreferredWidth(100); columna4.setMaxWidth(100); columna4.setMinWidth(100); // FECHA DE NACIMIENTO columna5 = tablaBibliotecario.getColumnModel().getColumn(4); columna5.setPreferredWidth(150); columna5.setMaxWidth(150); columna5.setMinWidth(150); // TELEFONO columna6 = tablaBibliotecario.getColumnModel().getColumn(5); columna6.setPreferredWidth(180); columna6.setMaxWidth(180); columna6.setMinWidth(180); // CORREO columna7 = tablaBibliotecario.getColumnModel().getColumn(6); columna7.setPreferredWidth(200); columna7.setMaxWidth(200); columna7.setMinWidth(200); }
// Set the width/height of columns/rows by the largest rendering entry private void customiseMinimumDimensions(Dimension dim, int row, int column) { TableColumn tableColumn = getColumnModel().getColumn(column); // this required extra margin padding is a mystery to me... dim.setSize(dim.width + getColumnMargin(), dim.height + getRowMargin()); // potential bug: refresh() is needed to reduce size of unusually large temporary entries if (tableColumn.getWidth() < dim.width) { tableColumn.setMinWidth(dim.width); if (column == 0) { tableColumn.setMaxWidth(dim.width); } } if (getRowHeight(row) < dim.height) { setRowHeight(row, dim.height); } }
private void setRootColumnSize(TableColumn column) { int rootWidth; if (!myUI.isMultipleRoots()) { rootWidth = 0; } else if (!myUI.isShowRootNames()) { rootWidth = ROOT_INDICATOR_WIDTH; } else { rootWidth = Math.min(calculateMaxRootWidth(), ROOT_NAME_MAX_WIDTH); } // NB: all further instructions and their order are important, otherwise the minimum size which // is less than 15 won't be applied column.setMinWidth(rootWidth); column.setMaxWidth(rootWidth); column.setPreferredWidth(rootWidth); }
ClauseOrder(QueryClauses clauses) { super(new GridLayout(1, 2)); this.clauses = clauses; DefaultPanel pnl; JToolBar bar; JScrollPane scroll; DefaultTableModel model = new DefaultTableModel(0, 2) { public boolean isCellEditable(int row, int column) { return column == 0; } }; this.add(pnl = new DefaultPanel()); pnl.setCenterComponent( scroll = new JScrollPane(availableExpressions = new JList(new DefaultListModel()))); pnl.setEastComponent(bar = new JToolBar(JToolBar.VERTICAL)); bar.add(createButton("put >", PUT)); bar.add(createButton("< push", PUSH)); bar.setFloatable(false); this.add(pnl = new DefaultPanel()); pnl.setCenterComponent(scroll = new JScrollPane(selectedExpressions = new JTable(model))); pnl.setEastComponent(bar = new JToolBar(JToolBar.VERTICAL)); bar.add(createButton("up", UP)); bar.add(createButton("down", DOWN)); bar.setFloatable(false); scroll.getViewport().setBackground(selectedExpressions.getBackground()); TableColumn tableColumn = selectedExpressions.getColumn(selectedExpressions.getColumnName(0)); tableColumn.setCellEditor(new CheckBoxCellRenderer()); tableColumn.setCellRenderer(new CheckBoxCellRenderer()); tableColumn.setPreferredWidth(15); tableColumn.setMaxWidth(15); tableColumn.setResizable(false); selectedExpressions.setIntercellSpacing(new Dimension(0, 0)); selectedExpressions.setShowGrid(false); selectedExpressions.setColumnSelectionAllowed(false); selectedExpressions.setDefaultRenderer(Boolean.class, new CheckBoxCellRenderer()); selectedExpressions.getTableHeader().setPreferredSize(new Dimension(0, 0)); selectedExpressions.getTableHeader().setVisible(false); }