public GUIRendWorkspace() { super("GUIRenderer"); createMenu(); workspaceModel.setTableFrame(this); add(new JScrollPane(workspaceTable)); workspaceTable .getColumnModel() .getColumn(0) .setCellEditor(new DefaultCellEditor(componentTypeEditor)); workspaceTable .getColumnModel() .getColumn(7) .setCellEditor(new DefaultCellEditor(componentFillEditor)); workspaceTable .getColumnModel() .getColumn(8) .setCellEditor(new DefaultCellEditor(componentAnchorEditor)); workspaceModel.addNewComponentEntry(); JButton newButton = new JButton(); newButton.addActionListener(new newComponent()); workspaceToolbar.add(newButton); add(workspaceToolbar, BorderLayout.NORTH); pack(); }
public CustomLeagueTable(String teamAmount) { model = new DefaultTableModel(); table = new JTable(model) { @Override public boolean isCellEditable(int row, int column) { return true; } }; model.setColumnIdentifiers( new String[] { "Team Name", "Points", "Goal Diff", "Wins", "Loses", "Draws", "Played", "League Verdict" }); model.setRowCount(Integer.parseInt(teamAmount)); JScrollPane pane = new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setPreferredSize(INITIAL_SIZE); setVisible(true); setLayout(new FlowLayout()); table.setRowSelectionAllowed(false); TableColumn colTeamName = table.getColumnModel().getColumn(0); colTeamName.setPreferredWidth(150); TableColumn colVerdict = table.getColumnModel().getColumn(4); colVerdict.setPreferredWidth(290); add(pane); }
@Override protected void customizeParametersTable( TableView<ParameterTableModelItemBase<ParameterInfoImpl>> table) { final JTable t = table.getComponent(); final TableColumn defaultValue = t.getColumnModel().getColumn(2); final TableColumn varArg = t.getColumnModel().getColumn(3); t.removeColumn(defaultValue); t.removeColumn(varArg); t.getModel() .addTableModelListener( new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.INSERT) { t.getModel().removeTableModelListener(this); final TableColumnAnimator animator = new TableColumnAnimator(t); animator.setStep(48); animator.addColumn(defaultValue, (t.getWidth() - 48) / 3); animator.addColumn(varArg, 48); animator.startAndDoWhenDone( new Runnable() { @Override public void run() { t.editCellAt(t.getRowCount() - 1, 0); } }); animator.start(); } } }); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (row % 2 == 1) { Color CorLinhas = new Color(225, 233, 255); setBackground(CorLinhas); } else { setBackground(null); } if (isSelected) { Color CorSelect = new Color(0, 152, 255); Color CorTexto = new Color(255, 255, 255); setBackground(CorSelect); setForeground(CorTexto); } else { setForeground(null); } DefaultTableCellRenderer esquerda = new DefaultTableCellRenderer(); DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer(); DefaultTableCellRenderer direita = new DefaultTableCellRenderer(); esquerda.setHorizontalAlignment(SwingConstants.LEFT); centralizado.setHorizontalAlignment(SwingConstants.CENTER); direita.setHorizontalAlignment(SwingConstants.RIGHT); table.getColumnModel().getColumn(0).setMaxWidth(141); table.getColumnModel().getColumn(0).setMinWidth(141); table.getColumnModel().getColumn(1).setMaxWidth(415); table.getColumnModel().getColumn(1).setMinWidth(415); return this; }
public CenterPanel(RegisterPanel rp) { super(); setLayout(new BorderLayout()); this.rp = rp; rp.setJT(jt); JScrollPane jsp = new JScrollPane(jt); setBackground(Color.BLACK); add(jsp, BorderLayout.CENTER); tm = (DefaultTableModel) jt.getModel(); tm.addColumn("ID"); tm.addColumn("Barcode"); tm.addColumn("Name"); tm.addColumn("Qty"); tm.addColumn("Price"); tm.addColumn("Tax"); tm.addColumn("Total"); // tm.setRowCount(50); // jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); jt.getColumnModel().getColumn(0).setPreferredWidth(20); jt.getColumnModel().getColumn(1).setPreferredWidth(150); jt.getColumnModel().getColumn(2).setPreferredWidth(300); jt.getColumnModel().getColumn(3).setPreferredWidth(20); jt.setFont(new Font("Arial", Font.BOLD, 18)); jt.setRowHeight(30); }
public void setModel(LogItemTableModel model) { this.model = model; logItemTable.setModel(model); logItemTable.getColumnModel().getColumn(0).setMinWidth(180); logItemTable.getColumnModel().getColumn(0).setMaxWidth(200); logItemTable.getColumnModel().getColumn(1).setMinWidth(50); logItemTable.getColumnModel().getColumn(1).setMaxWidth(80); logItemTable.setDefaultRenderer(Object.class, new LogEntryRenderer()); }
private void setTableColumnWidths() { table.sizeColumnsToFit(JTable.AUTO_RESIZE_NEXT_COLUMN); TableColumn column = null; column = table.getColumnModel().getColumn(0); column.setMinWidth(KEY_COL_WIDTH); column.setPreferredWidth(KEY_COL_WIDTH); column = table.getColumnModel().getColumn(1); column.setPreferredWidth(VAL_COL_WIDTH); }
protected void setupTable(JTable table) { table.setFillsViewportHeight(true); table.getColumnModel().getColumn(2).setMaxWidth(150); table.getColumnModel().getColumn(1).setMaxWidth(150); table.getColumnModel().getColumn(0).setMaxWidth(150); // table.getColumnModel().getColumn(0).setPreferredWidth(10); table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); }
{ table = new JTable(); model.setErrors(errors); table.setModel(model); TableColumn detailsColumn = table.getColumnModel().getColumn(1); detailsColumn.setCellEditor(new DetailRenderer()); detailsColumn.setCellRenderer(new DetailRenderer()); detailsColumn.setPreferredWidth(15); table.getColumnModel().getColumn(0).setPreferredWidth(DEFAULT_FIRST_COMUMN_WIDTH); }
private void modelsChanged() { TableColumn col = dataTable.getColumnModel().getColumn(5); col.setCellEditor(new ComboBoxCellEditor()); col = dataTable.getColumnModel().getColumn(6); col.setCellEditor(new ComboBoxCellEditor()); col = dataTable.getColumnModel().getColumn(7); col.setCellEditor( new DefaultCellEditor(new JComboBox(options.getNonTraitPartitionTreeModels().toArray()))); }
// This method from http://www.exampledepot.com/egs/javax.swing.table/PackCol.html public int packColumn(JTable table, int vColIndex, int margin) { DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(vColIndex); int width = 0; // Get width of column header TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); width = comp.getPreferredSize().width; // Get maximum width of column data for (int r = 0; r < table.getRowCount(); r++) { renderer = table.getCellRenderer(r, vColIndex); comp = renderer.getTableCellRendererComponent( table, table.getValueAt(r, vColIndex), false, false, r, vColIndex); width = Math.max(width, comp.getPreferredSize().width); } // Add margin width += 2 * margin; // Set the width col.setPreferredWidth(width); return width; }
/** * This method implements the TableModelListener * * @param e The event to listen for. */ @Override public void tableChanged(TableModelEvent e) { if (!isColumnDataIncluded) { return; } // A cell has been updated if (e.getType() == TableModelEvent.UPDATE) { int column = table.convertColumnIndexToView(e.getColumn()); // Only need to worry about an increase in width for this cell if (isOnlyAdjustLarger) { int row = e.getFirstRow(); TableColumn tableColumn = table.getColumnModel().getColumn(column); if (tableColumn.getResizable()) { int width = getCellDataWidth(row, column); updateTableColumn(column, width); } } // Could be an increase of decrease so check all rows else { adjustColumn(column); } } // The update affected more than one column so adjust all columns else { adjustColumns(); } }
public void setMetricsResults(MetricDisplaySpecification displaySpecification, MetricsRun run) { final MetricCategory[] categories = MetricCategory.values(); for (final MetricCategory category : categories) { final JTable table = tables.get(category); final String type = MetricsCategoryNameUtil.getShortNameForCategory(category); final MetricTableSpecification tableSpecification = displaySpecification.getSpecification(category); final MetricsResult results = run.getResultsForCategory(category); final MetricTableModel model = new MetricTableModel(results, type, tableSpecification); table.setModel(model); final Container tab = table.getParent().getParent(); if (model.getRowCount() == 0) { tabbedPane.remove(tab); continue; } final String longName = MetricsCategoryNameUtil.getLongNameForCategory(category); tabbedPane.add(tab, longName); final MyColumnListener columnListener = new MyColumnListener(tableSpecification, table); final TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(columnListener); final int columnCount = columnModel.getColumnCount(); for (int i = 0; i < columnCount; i++) { final TableColumn column = columnModel.getColumn(i); column.addPropertyChangeListener(columnListener); } setRenderers(table, type); setColumnWidths(table, tableSpecification); } }
public void adjustColumns() { TableColumnModel tcm = table.getColumnModel(); for (int i = 0; i < tcm.getColumnCount(); i++) { adjustColumn(i); } }
public TableCellRenderFrame() { 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<Integer> moonCombo = new JComboBox<>(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i); 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(getClass().getResource("Moons.gif"))); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
private Component iciciCodeMappings() { java.util.List<TableDisplayInput> displayInputs = new ArrayList<TableDisplayInput>(); displayInputs.add(new StringDisplayInput("ICICICode", "getIciciCode")); displayInputs.add(new StringDisplayInput("StockCode", "getStockCode")); List<ICICICodeMapping> list = Controller.getIciciMappings(); PMTableModel tableModel = new PMTableModel(list, displayInputs, false) { @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return columnIndex == 1; } @Override public void setValueAt(Object value, int rowIndex, int columnIndex) { ((ICICICodeMapping) dataVOs.get(rowIndex)).setStock((StockVO) value); } }; table = UIHelper.createTable(tableModel); table .getColumnModel() .getColumn(1) .setCellEditor(new DefaultCellEditor(UIHelper.createStockVOlistJCB())); return UIHelper.createScrollPane(table); }
BusinessPane() { setLayout(null); add(info_label); info_label.setBounds(10, 10, 300, 20); info_label.setFont(new Font("TimesRoman", Font.BOLD, 12)); add(info_scroll); info_scroll.setBounds(5, 35, 615, 400); info_name.add(columnName[0]); info_name.add(columnName[1]); info_name.add(columnName[2]); info_name.add(columnName[3]); DefaultTableModel info_model = new DefaultTableModel(info_data, info_name); info_table.setModel(info_model); info_table.getColumnModel().getColumn(0).setWidth(25); info_table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { // click to trigger the event // show_selected(); // System.out.print(table_selected(0)); } } }); add(B_refresh); B_refresh.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_refresh.setBounds(530, 440, 90, 25); B_refresh.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { update_table(); } }); }
public ChartLegend(PrideChartManager managedPrideChart) { super(new BorderLayout()); Dimension dimension = new Dimension(200, 50); PrideChartLegend pcl = (PrideChartLegend) managedPrideChart.getPrideChart(); setVisible(managedPrideChart.isLegendVisible()); JTable chartLegend = new JTable(); DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(pcl.getColumnNames()); for (Object left : pcl.getOrderedLegend()) { String right = pcl.getLegendMeaning(left.toString()); model.addRow(new Object[] {left, right}); } chartLegend.setModel(model); // chartLegend.setAutoCreateRowSorter(false); chartLegend.setFillsViewportHeight(true); chartLegend.getColumnModel().getColumn(0).setMaxWidth(100); JScrollPane scrollPane = new JScrollPane( chartLegend, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.add(scrollPane, BorderLayout.CENTER); this.setPreferredSize(dimension); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { textLabel.setFont(table.getFont()); textLabel.setText(Objects.toString(value, "")); textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder); FontMetrics fm = table.getFontMetrics(table.getFont()); Insets i = textLabel.getInsets(); int swidth = iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right; int cwidth = table.getColumnModel().getColumn(column).getWidth(); dim.width = swidth > cwidth ? cwidth : swidth; if (isSelected) { textLabel.setOpaque(true); textLabel.setForeground(table.getSelectionForeground()); textLabel.setBackground(table.getSelectionBackground()); iconLabel.setIcon(sicon); } else { textLabel.setOpaque(false); textLabel.setForeground(table.getForeground()); textLabel.setBackground(table.getBackground()); iconLabel.setIcon(nicon); } return panel; }
public LeagueTable() { model = new DefaultTableModel(); model.setColumnIdentifiers( new String[] { "Team Name", "Points", "Goal Diff", "Wins", "Draws", "Loses", "Played", "League Verdict" }); table = new JTable(model) { @Override public boolean isCellEditable(int row, int column) { return false; } }; JScrollPane pane = new JScrollPane( table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setPreferredSize(INITIAL_SIZE); setVisible(true); setLayout(new FlowLayout()); TableColumn colVerdict = table.getColumnModel().getColumn(7); colVerdict.setPreferredWidth(290); add(pane); }
private void init() { agents = new JComboBox(model); agents.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stateChanged(event); } }); agents.addActionListener(TextChangesListener.getInstance()); ctm = new CreationTableModel(); datatable = new JTable(ctm); datatable.setShowGrid(false); datatable.setEnabled(false); datatable.setTableHeader(null); datatable.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); JPanel apanel = new JPanel(new BorderLayout()); apanel.add(new JLabel("Who took the photo: "), BorderLayout.WEST); apanel.add(agents, BorderLayout.CENTER); JPanel tablePanel = new JPanel(new BorderLayout()); tablePanel.add(new JScrollPane(datatable), BorderLayout.CENTER); datatable.getColumnModel().getColumn(0).setMaxWidth(120); datatable.getColumnModel().getColumn(0).setMinWidth(80); datatable.addKeyListener(TextChangesListener.getInstance()); this.add( ComponentFactory.createTitledPanel("Creator of the image:", apanel), BorderLayout.NORTH); this.add( ComponentFactory.createTitledPanel("Creation, EXIF & technical information:", tablePanel), BorderLayout.CENTER); this.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.WEST); }
private void packColumn(JTable table, int colIndex, int margin) { int width = Math.max(getColumnHeaderWidth(table, colIndex), getColumnCellWidth(table, colIndex)); width += 2 * margin; TableColumn column = table.getColumnModel().getColumn(colIndex); column.setPreferredWidth(width); // todo column.setMaxWidth(width); }
private int getColumnHeaderWidth(JTable table, int colIndex) { TableColumn col = table.getColumnModel().getColumn(colIndex); TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) renderer = table.getTableHeader().getDefaultRenderer(); Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); return comp.getPreferredSize().width; }
/** Creates and displays the main GUI This GUI has the list and the main * buttons */ public void showGUI() { final JScrollPane scrollPane = new JScrollPane(); table = new JTable( new DefaultTableModel( new Object[][] {}, new String[] {"Username", "Password", "Pin", "Reward"})); AccountManager.loadAccounts(); if (AccountManager.hasAccounts()) { for (Account account : AccountManager.getAccounts()) { ((DefaultTableModel) table.getModel()) .addRow( new Object[] { account.getUsername(), account.getReward(), account.getPin(), account.getReward() }); } } final JToolBar bar = new JToolBar(); bar.setMargin(new Insets(1, 1, 1, 1)); bar.setFloatable(false); removeButton = new JButton("Remove"); final JButton newButton = new JButton("Add"); final JButton doneButton = new JButton("Save"); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new TableSelectionListener()); table.setShowGrid(true); final TableColumnModel cm = table.getColumnModel(); cm.getColumn(cm.getColumnIndex("Password")).setCellRenderer(new PasswordCellRenderer()); cm.getColumn(cm.getColumnIndex("Password")).setCellEditor(new PasswordCellEditor()); cm.getColumn(cm.getColumnIndex("Pin")).setCellRenderer(new PasswordCellRenderer()); cm.getColumn(cm.getColumnIndex("Pin")).setCellEditor(new PasswordCellEditor()); cm.getColumn(cm.getColumnIndex("Reward")).setCellEditor(new RandomRewardEditor()); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setViewportView(table); add(scrollPane, BorderLayout.CENTER); newButton.setFocusable(false); newButton.setToolTipText(newButton.getText()); newButton.setText("+"); bar.add(newButton); removeButton.setFocusable(false); removeButton.setToolTipText(removeButton.getText()); removeButton.setText("-"); bar.add(removeButton); bar.add(Box.createHorizontalGlue()); doneButton.setToolTipText(doneButton.getText()); bar.add(doneButton); newButton.addActionListener(this); removeButton.addActionListener(this); doneButton.addActionListener(this); add(bar, BorderLayout.SOUTH); final int row = table.getSelectedRow(); removeButton.setEnabled(row >= 0 && row < table.getRowCount()); table.clearSelection(); doneButton.requestFocus(); setPreferredSize(new Dimension(600, 300)); pack(); setLocationRelativeTo(getOwner()); setResizable(false); }
/** * This method restores the width of the specified column to its previous width. * * @param column The column to restore. */ private void restoreColumn(int column) { TableColumn tableColumn = table.getColumnModel().getColumn(column); Integer width = columnSizes.get(tableColumn); if (width != null) { table.getTableHeader().setResizingColumn(tableColumn); tableColumn.setWidth(width.intValue()); } }
private void createGUI() { configTable = new JTable(new ConfigTableModel()); getContentPane().add(configTable); // initialize columns String[] dimensionTypeNames = new String[] {"SRCIP", "DSTIP", "PROTO", "SRCPORT", "DSTPORT", "Custom"}; TableColumn dimensionType = configTable.getColumnModel().getColumn(0); dimensionType.setCellEditor(new MyComboBoxEditor(dimensionTypeNames)); dimensionType.setCellRenderer(new MyComboBoxRenderer(dimensionTypeNames)); }
private static int calcMaxWidth(JTable table) { int colsNum = table.getColumnModel().getColumnCount(); int totalWidth = 0; for (int col = 0; col < colsNum - 1; col++) { TableColumn column = table.getColumnModel().getColumn(col); int preferred = column.getPreferredWidth(); int width = Math.max(preferred, columnMaxWidth(table, col)); totalWidth += width; column.setMinWidth(width); column.setMaxWidth(width); column.setWidth(width); column.setPreferredWidth(width); } totalWidth += columnMaxWidth(table, colsNum - 1); return totalWidth; }
@Override protected int getMaxAvailablePageWidth( Page page, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return table.getColumnModel().getColumn(column).getWidth(); }
private static int columnMaxWidth(@NotNull JTable table, int col) { TableColumn column = table.getColumnModel().getColumn(col); int width = 0; for (int row = 0; row < table.getRowCount(); row++) { Component component = table.prepareRenderer(column.getCellRenderer(), row, col); int rendererWidth = component.getPreferredSize().width; width = Math.max(width, rendererWidth + table.getIntercellSpacing().width); } return width; }
@NotNull private static MyModel setTableModel( @NotNull JTable table, @NotNull UsageViewImpl usageView, @NotNull final List<UsageNode> data) { ApplicationManager.getApplication().assertIsDispatchThread(); final int columnCount = calcColumnCount(data); MyModel model = table.getModel() instanceof MyModel ? (MyModel) table.getModel() : null; if (model == null || model.getColumnCount() != columnCount) { model = new MyModel(data, columnCount); table.setModel(model); ShowUsagesTableCellRenderer renderer = new ShowUsagesTableCellRenderer(usageView); for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } } return model; }