List of usage examples for javax.swing.table TableColumn setCellRenderer
@BeanProperty(description = "The renderer to use for cell values.") public void setCellRenderer(TableCellRenderer cellRenderer)
TableCellRenderer
used by JTable
to draw individual values for this column. From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java
private void initModels() { TableFormat<Operation> operationsTableFormat = GlazedLists.tableFormat(Operation.class, new String[] { "name", "relativeClientLoad" }, new String[] { "Name", "Rel. Client Load" }, new boolean[] { true, true }); EventTableModel<Operation> operationsModel = new EventTableModel<Operation>(operations, operationsTableFormat);//w ww . ja va2 s .c om tblOperations.setModel(operationsModel); tblOperations.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); tblOperations.setColumnWidths(300, 100); tblOperations.getColumnModel().getColumn(0).setCellEditor(new StringCellEditor(tblOperations, operations)); TableColumn column = tblOperations.getColumnModel().getColumn(1); column.setCellEditor(new DoubleCellEditor()); column.setCellRenderer(new DoubleCellRenderer()); TableFormat<Target> targetsTableFormat = GlazedLists.tableFormat(Target.class, new String[] { "name", "loadPart" }, new String[] { "Name", "Load Part" }, new boolean[] { true, true }); EventTableModel<Target> targetsModel = new EventTableModel<Target>(targets, targetsTableFormat); tblTargets.setModel(targetsModel); tblTargets.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); tblTargets.setColumnWidths(300, 100); tblTargets.getColumnModel().getColumn(0).setCellEditor(new StringCellEditor(tblTargets, targets)); column = tblTargets.getColumnModel().getColumn(1); column.setCellEditor(new DoubleCellEditor()); column.setCellRenderer(new DoubleCellRenderer()); TableFormat<Client> clientsTableFormat = GlazedLists.tableFormat(Client.class, new String[] { "daemonId", "name", "numProcesses", "relativePower" }, new String[] { "Daemon ID", "Name", "# of Processes", "Rel. Power" }, new boolean[] { false, true, true, true }); EventTableModel<Client> clientsModel = new EventTableModel<Client>(clients, clientsTableFormat); tblClients.setModel(clientsModel); tblClients.setColumnWidths(80, 200, 80, 60); tblClients.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // tblClients.getColumnModel().getColumn(0).setCellEditor(new IntegerCellEditor()); tblClients.getColumnModel().getColumn(1).setCellEditor(new StringCellEditor(tblClients, clients)); tblClients.getColumnModel().getColumn(2).setCellEditor(new IntegerCellEditor()); column = tblClients.getColumnModel().getColumn(3); column.setCellEditor(new DoubleCellEditor()); column.setCellRenderer(new DoubleCellRenderer()); cboConfigurationFile.setModel(new EventComboBoxModel<String>(configFiles)); cboConfigurationFile.setSelectedItem(controller.getActiveSettingsFile()); }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
public TrialSelectionDialog(Window owner, String title, DALClient c, List<Trial> kdxTrials, Transformer<BackgroundRunner, TrialSearchOptionsPanel> searchOptionsPanelFactory) { super(owner, title, USE_TRIALS); setGlassPane(backgroundRunner.getBlockingPane()); searchOptionsPanel = searchOptionsPanelFactory.transform(backgroundRunner); helpInstructions = new JLabel(searchOptionsPanel.getHtmlHelp(GET_TRIALS)); kdxTrialByIdDownloaded = kdxTrials.stream().filter(t -> t.getIdDownloaded() != null) .collect(Collectors.toMap(Trial::getIdDownloaded, java.util.function.Function.identity())); trialRecordTable.setName(this.getClass().getName() + ".trialRecordTable"); //$NON-NLS-1$ TableColumnModel tcm = trialRecordTable.getColumnModel(); TableCellRenderer cellRenderer = new OptionalCheckboxRenderer("Already downloaded"); tcm.getColumn(trialRecordTableModel.getChosenColumnIndex()).setCellRenderer(cellRenderer); for (int col = tcm.getColumnCount(); --col >= 0;) { if ("TrialName".equals(trialRecordTable.getColumnName(col))) { TableColumn tc = tcm.getColumn(col); tc.setCellRenderer(new TrialNameCellRenderer()); break; }// w ww . j a v a 2 s. com } findTrialRecords.setEnabled(false); searchOptionsPanel.addSearchOptionsChangeListener(searchOptionsListener); wantTrialUnits.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filteringClauseUsed = null; handleSearchOptionsChoiceChanged(); } }); setDALClient(c); initialiseGui(); if (owner != null) { Dimension ownerSize = owner.getSize(); Dimension mySize = getSize(); int w = (ownerSize.width * 3) / 4; int h = (ownerSize.height * 3) / 4; if (w > mySize.width || h > mySize.height) { if (w > mySize.width) { mySize.width = w; } if (h > mySize.height) { mySize.height = h; } setSize(mySize); } } // TODO consider using setSize to increase to parent's width getOkAction().setEnabled(false); trialRecordTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { getOkAction().setEnabled(trialRecordTableModel.getAnyChosen()); } }); }
From source file:TableRenderDemo.java
public void setUpSportColumn(JTable table, TableColumn sportColumn) { // Set up the editor for the sport cells. JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); // Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); sportColumn.setCellRenderer(renderer); }
From source file:mekhq.gui.FinancesTab.java
@Override public void initTab() { resourceMap = ResourceBundle.getBundle("mekhq.resources.FinancesTab", new EncodeControl()); //$NON-NLS-1$ GridBagConstraints gridBagConstraints; setLayout(new GridBagLayout()); ChartPanel financeAmountPanel = (ChartPanel) createGraphPanel(GraphType.BALANCE_AMOUNT); ChartPanel financeMonthlyPanel = (ChartPanel) createGraphPanel(GraphType.MONTHLY_FINANCES); financeModel = new FinanceTableModel(); financeTable = new JTable(financeModel); financeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); financeTable.addMouseListener(new FinanceTableMouseAdapter(getCampaignGui(), financeTable, financeModel)); financeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); TableColumn column = null; for (int i = 0; i < FinanceTableModel.N_COL; i++) { column = financeTable.getColumnModel().getColumn(i); column.setPreferredWidth(financeModel.getColumnWidth(i)); column.setCellRenderer(financeModel.getRenderer()); }/* w ww .jav a 2 s. co m*/ financeTable.setIntercellSpacing(new Dimension(0, 0)); financeTable.setShowGrid(false); loanModel = new LoanTableModel(); loanTable = new JTable(loanModel); loanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); loanTable.addMouseListener(new LoanTableMouseAdapter(getCampaignGui(), loanTable, loanModel)); loanTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); column = null; for (int i = 0; i < LoanTableModel.N_COL; i++) { column = loanTable.getColumnModel().getColumn(i); column.setPreferredWidth(loanModel.getColumnWidth(i)); column.setCellRenderer(loanModel.getRenderer()); } loanTable.setIntercellSpacing(new Dimension(0, 0)); loanTable.setShowGrid(false); JScrollPane scrollLoanTable = new JScrollPane(loanTable); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; JPanel panBalance = new JPanel(new GridBagLayout()); panBalance.add(new JScrollPane(financeTable), gridBagConstraints); panBalance.setMinimumSize(new java.awt.Dimension(350, 100)); panBalance.setBorder(BorderFactory.createTitledBorder("Balance Sheet")); JPanel panLoan = new JPanel(new GridBagLayout()); panLoan.add(scrollLoanTable, gridBagConstraints); JTabbedPane financeTab = new JTabbedPane(); financeTab.setMinimumSize(new java.awt.Dimension(450, 300)); financeTab.setPreferredSize(new java.awt.Dimension(450, 300)); JSplitPane splitFinances = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panBalance, financeTab); splitFinances.setOneTouchExpandable(true); splitFinances.setContinuousLayout(true); splitFinances.setResizeWeight(1.0); splitFinances.setName("splitFinances"); financeTab.addTab(resourceMap.getString("activeLoans.text"), panLoan); financeTab.addTab(resourceMap.getString("cbillsBalanceTime.text"), financeAmountPanel); financeTab.addTab(resourceMap.getString("monthlyRevenueExpenditures.text"), financeMonthlyPanel); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(splitFinances, gridBagConstraints); JPanel panelFinanceRight = new JPanel(new BorderLayout()); JPanel pnlFinanceBtns = new JPanel(new GridLayout(2, 2)); btnAddFunds = new JButton("Add Funds (GM)"); btnAddFunds.addActionListener(ev -> addFundsActionPerformed()); btnAddFunds.setEnabled(getCampaign().isGM()); pnlFinanceBtns.add(btnAddFunds); JButton btnGetLoan = new JButton("Get Loan"); btnGetLoan.addActionListener(e -> showNewLoanDialog()); pnlFinanceBtns.add(btnGetLoan); btnManageAssets = new JButton("Manage Assets (GM)"); btnManageAssets.addActionListener(e -> manageAssets()); btnManageAssets.setEnabled(getCampaign().isGM()); pnlFinanceBtns.add(btnManageAssets); panelFinanceRight.add(pnlFinanceBtns, BorderLayout.NORTH); areaNetWorth = new JTextArea(); areaNetWorth.setLineWrap(true); areaNetWorth.setWrapStyleWord(true); areaNetWorth.setFont(new Font("Courier New", Font.PLAIN, 12)); areaNetWorth.setText(getCampaign().getFinancialReport()); areaNetWorth.setEditable(false); JScrollPane descriptionScroll = new JScrollPane(areaNetWorth); panelFinanceRight.add(descriptionScroll, BorderLayout.CENTER); areaNetWorth.setCaretPosition(0); descriptionScroll.setMinimumSize(new Dimension(300, 200)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 0.0; gridBagConstraints.weighty = 1.0; add(panelFinanceRight, gridBagConstraints); }
From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java
public TraitsAndInstancesPanel2(CurationContext cc, Font smallFont, TIStatsTableModel tistm, boolean anyInstanceNumbers, int nInvalidRules, String tAndIpanelLabel, CurationMenuProvider curationMenuProvider, Consumer<List<OutlierSelection>> outlierConsumer) { super(new BorderLayout()); this.curationContext = cc; this.outlierConsumer = outlierConsumer; this.curationMenuProvider = curationMenuProvider; this.tiStatsModel = tistm; curationContext.addPropertyChangeListener(propertyChangeListener); traitInstanceStatsTable = new TraitInstanceStatsTable(tiStatsModel); traitInstanceStatsTable.addPropertyChangeListener("rowSorter", rowSorterChangeListener); traitInstanceStatsTable.setAutoCreateRowSorter(true); traitInstanceStatsTable.addMouseListener(new MouseAdapter() { @Override/*from w w w .ja v a 2s. c o m*/ public void mouseClicked(MouseEvent me) { int clickCount = me.getClickCount(); if (SwingUtilities.isRightMouseButton(me) && 1 == clickCount) { me.consume(); showContextMenu(me); } else if (SwingUtilities.isLeftMouseButton(me) && 2 == clickCount) { showTraitInstanceInfo(me); } } }); Map<String, TableColumn[]> tableColumnsByChoice = createInstanceTableColumnsByChoice(); TableColumnSelectionButton tcsb = new TableColumnSelectionButton(traitInstanceStatsTable, tableColumnsByChoice); StringCellRenderer scRenderer = new StringCellRenderer(); scRenderer.setHorizontalAlignment(SwingConstants.CENTER); statDetailRenderer.setHorizontalAlignment(SwingConstants.CENTER); traitInstanceStatsTable.setDefaultRenderer(String.class, scRenderer); Transformer<TraitInstance, String> instanceNameTransformer = new Transformer<TraitInstance, String>() { @Override public String transform(TraitInstance ti) { return curationContext.makeTraitInstanceName(ti); } }; TraitInstanceCellRenderer tiRenderer = new TraitInstanceCellRenderer( curationContext.getTraitColorProvider(), instanceNameTransformer); tiRenderer.setName("FOR-STATS-TABLE"); //$NON-NLS-1$ traitInstanceStatsTable.setDefaultRenderer(TraitInstance.class, tiRenderer); traitInstanceStatsTable.setDefaultRenderer(Comparable.class, statDetailRenderer); TableColumnModel tcm = traitInstanceStatsTable.getColumnModel(); Integer viewColumnIndex = tistm.getViewColumnIndex(); if (viewColumnIndex != null) { TableColumn viewColumn = tcm.getColumn(viewColumnIndex); viewColumn.setMaxWidth(40); viewColumn.setCellRenderer(new OptionalCheckboxRenderer("No Values")); } if (nInvalidRules <= 0) { // Hide that column! int columnIndex = tistm.getValRuleErrorColumnIndex(); columnIndex = traitInstanceStatsTable.convertColumnIndexToView(columnIndex); if (columnIndex >= 0) { TableColumn c = tcm.getColumn(columnIndex); tcm.removeColumn(c); } } TableColumn dataTypeTableColumn = traitInstanceStatsTable.getColumnModel() .getColumn(tistm.getTraitInstanceDatatypeColumnIndex()); dataTypeTableColumn.setCellRenderer(new TraitDataTypeRenderer()); Function<JTable, JScrollPane> scrollMaker = new Function<JTable, JScrollPane>() { @Override public JScrollPane apply(JTable t) { return new PromptScrollPane(t, "Select Trait in the Panel: " + tAndIpanelLabel); } }; TitledTablePanelWithResizeControls ttp = new TitledTablePanelWithResizeControls("Trait Instances", traitInstanceStatsTable, smallFont, scrollMaker); ttp.scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); ttp.scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, tcsb); new CurationContextOptionsPopup(curationContext, ttp.separator); if (anyInstanceNumbers) { tcsb.setSelectedColumns(SimpleStatistics.GROUP_BASIC_STATS); } else { Set<Object> headerValues = new HashSet<>(); for (TableColumn tc : tableColumnsByChoice.get(SimpleStatistics.GROUP_BASIC_STATS)) { headerValues.add(tc.getHeaderValue()); } headerValues.remove(tistm.getInstanceHeading()); tcsb.initialiseSelectedColumns(new Predicate<Object>() { @Override public boolean evaluate(Object hvalue) { return headerValues.contains(hvalue); } }); } add(ttp, BorderLayout.CENTER); }
From source file:components.TableRenderDemo.java
public void setUpSportColumn(JTable table, TableColumn sportColumn) { //Set up the editor for the sport cells. JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); //Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); sportColumn.setCellRenderer(renderer); }
From source file:logdruid.ui.table.EventRecordingEditorTable.java
public void setUpProcessingColumn(JTable theTable, TableColumn typeColumn) { JComboBox functionComboBox = new JComboBox(); functionComboBox.addItem("capture"); functionComboBox.addItem("duration"); functionComboBox.addItem("occurrences"); functionComboBox.addItem("sum"); typeColumn.setCellEditor(new DefaultCellEditor(functionComboBox)); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); typeColumn.setCellRenderer(renderer); }
From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java
public DirectoryBrowser(UserPreferences preferences, File directory) { Validate.notNull(preferences, "The given user preferences are null"); Validate.notNull(directory, "The given directory is null"); Validate.isTrue(directory.exists(),/* w ww. j a v a 2 s . co m*/ String.format("The given directory '%s' doesn't exist", directory.getAbsolutePath())); Validate.isTrue(directory.isDirectory(), String.format("The given path '%s' doesn't denote a directory", directory.getAbsolutePath())); this.preferences = preferences; // Layout, columns & rows setLayout(new MigLayout("insets 0px", "[grow]", "[]1[grow]1[]")); this.tableModel = new FileTableModel(this); this.table = new JTable(tableModel); this.table.setBackground(Utils.getDefaultBackgroundColor()); this.table.addKeyListener(this); this.table.addMouseListener(this); this.table.addFocusListener(this); this.table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.table.getSelectionModel().addListSelectionListener(this); // Listen to column event resize events final ColumnEventHelper eventHelper = new ColumnEventHelper(this); this.table.getColumnModel().addColumnModelListener(eventHelper); this.table.getTableHeader().addMouseListener(eventHelper); // Render the table headers with a bold font this.table.getTableHeader().setFont(Utils.getBoldFont(this.table.getTableHeader().getFont())); this.table.getTableHeader().setBackground(Utils.getDefaultBackgroundColor()); this.table.getTableHeader().setDefaultRenderer(new TableHeaderRenderer()); this.table.getTableHeader().addMouseListener(this); final TableColumn typeColumn = this.table.getColumn(FileTableModel.COLUMN_TYPE); typeColumn.setCellRenderer(new FileTypeRenderer()); typeColumn.setResizable(false); typeColumn.setHeaderValue(""); typeColumn.setMaxWidth(Icons.FOLDER_ICON.getIconWidth() + 5); final TableColumn fileColumn = this.table.getColumn(FileTableModel.COLUMN_NAME); fileColumn.setCellRenderer(new FileNameRenderer()); fileColumn.setResizable(true); final TableColumn sizeColumn = this.table.getColumn(FileTableModel.COLUMN_SIZE); sizeColumn.setCellRenderer(new FileSizeRenderer()); sizeColumn.setResizable(true); // Dynamically set the column to the correct size final TableColumn lastUpdateColumn = this.table.getColumn(FileTableModel.COLUMN_LAST_UPDATE); lastUpdateColumn.setCellRenderer(new LastUpdateRenderer()); lastUpdateColumn.setResizable(false); lastUpdateColumn.setMaxWidth(Utils.getTimestampRenderWidth() + 5); lastUpdateColumn.setMinWidth(Utils.getTimestampRenderWidth() + 5); // Use a square border (not one with rounded corners) this.directoryButton.setBorder(Utils.createRaisedBevelBorder()); this.directoryButton.setFont(Utils.getDefaultFont()); this.directoryButton.setFocusable(false); this.directoryButton.setHorizontalAlignment(SwingConstants.LEFT); this.summary = new JLabel(" "); this.summary.setBorder(Utils.createRaisedBevelBorder()); add(directoryButton, "grow, wrap"); add(new JScrollPane(table), "grow, wrap"); add(summary, "grow"); // Set the directory (this will populate the table) setDirectory(directory); }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);/*from ww w. j av a 2 s . co m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
From source file:com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel.java
private void updateTableColumn() { TableColumn hidden = jobConfigurationTable.getColumnModel().getColumn(InteractiveTableModel.HIDDEN_INDEX); hidden.setMinWidth(2);/* w w w . j a v a 2 s.c o m*/ hidden.setPreferredWidth(2); hidden.setMaxWidth(2); hidden.setCellRenderer(new InteractiveRenderer(InteractiveTableModel.HIDDEN_INDEX)); TableColumn keyColumn = jobConfigurationTable.getColumnModel().getColumn(InteractiveTableModel.KEY_INDEX); keyColumn.setCellRenderer(new InteractiveRenderer(InteractiveTableModel.KEY_INDEX)); if (updateCallBack != null) { updateCallBack.run(); } }