List of usage examples for javax.swing JTable getColumn
public TableColumn getColumn(Object identifier)
TableColumn
object for the column in the table whose identifier is equal to identifier
, when compared using equals
. From source file:captureplugin.CapturePlugin.java
/** * Check the programs after data update. *//*from ww w. j ava 2 s . c o m*/ public void handleTvDataUpdateFinished() { mNeedsUpdate = true; if (mAllowedToShowDialog) { mNeedsUpdate = false; DeviceIf[] devices = mConfig.getDeviceArray(); final DefaultTableModel model = new DefaultTableModel() { public boolean isCellEditable(int row, int column) { return false; } }; model.setColumnCount(5); model.setColumnIdentifiers(new String[] { mLocalizer.msg("device", "Device"), Localizer.getLocalization(Localizer.I18N_CHANNEL), mLocalizer.msg("date", "Date"), ProgramFieldType.START_TIME_TYPE.getLocalizedName(), ProgramFieldType.TITLE_TYPE.getLocalizedName() }); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); table.getTableHeader().setResizingAllowed(false); table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable renderTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(renderTable, value, isSelected, hasFocus, row, column); if (value instanceof DeviceIf) { if (((DeviceIf) value).getDeleteRemovedProgramsAutomatically() && !isSelected) { c.setForeground(Color.red); } } return c; } }); int[] columnWidth = new int[5]; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = UiUtilities.getStringWidth(table.getFont(), model.getColumnName(i)) + 10; } for (DeviceIf device : devices) { Program[] deleted = device.checkProgramsAfterDataUpdateAndGetDeleted(); if (deleted != null && deleted.length > 0) { for (Program p : deleted) { if (device.getDeleteRemovedProgramsAutomatically() && !p.isExpired() && !p.isOnAir()) { device.remove(UiUtilities.getLastModalChildOf(getParentFrame()), p); } else { device.removeProgramWithoutExecution(p); } if (!p.isExpired()) { Object[] o = new Object[] { device, p.getChannel().getName(), p.getDateString(), p.getTimeString(), p.getTitle() }; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = Math.max(columnWidth[i], UiUtilities.getStringWidth(table.getFont(), o[i].toString()) + 10); } model.addRow(o); } } } device.getProgramList(); } if (model.getRowCount() > 0) { int sum = 0; for (int i = 0; i < columnWidth.length; i++) { table.getColumnModel().getColumn(i).setPreferredWidth(columnWidth[i]); if (i < columnWidth.length - 1) { table.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]); } sum += columnWidth[i]; } JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(450, 250)); if (sum > 500) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrollPane.getViewport().setPreferredSize( new Dimension(sum, scrollPane.getViewport().getPreferredSize().height)); } JButton export = new JButton(mLocalizer.msg("exportList", "Export list")); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.toString().toLowerCase().endsWith(".txt"); } public String getDescription() { return "*.txt"; } }); chooser.setSelectedFile(new File("RemovedPrograms.txt")); if (chooser.showSaveDialog( UiUtilities.getLastModalChildOf(getParentFrame())) == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { String file = chooser.getSelectedFile().getAbsolutePath(); if (!file.toLowerCase().endsWith(".txt") && file.indexOf('.') == -1) { file = file + ".txt"; } if (file.indexOf('.') != -1) { try { RandomAccessFile write = new RandomAccessFile(file, "rw"); write.setLength(0); String eolStyle = File.separator.equals("/") ? "\n" : "\r\n"; for (int i = 0; i < model.getRowCount(); i++) { StringBuilder line = new StringBuilder(); for (int j = 0; j < model.getColumnCount(); j++) { line.append(model.getValueAt(i, j)).append(' '); } line.append(eolStyle); write.writeBytes(line.toString()); } write.close(); } catch (Exception ee) { } } } } } }); Object[] message = { mLocalizer.msg("deletedText", "The data was changed and the following programs were deleted:"), scrollPane, export }; JOptionPane pane = new JOptionPane(); pane.setMessage(message); pane.setMessageType(JOptionPane.PLAIN_MESSAGE); final JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(getParentFrame()), mLocalizer.msg("CapturePlugin", "CapturePlugin") + " - " + mLocalizer.msg("deletedTitle", "Deleted programs")); d.setResizable(true); d.setModal(false); SwingUtilities.invokeLater(new Runnable() { public void run() { d.setVisible(true); } }); } } }
From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzResultDialog.java
@Override public JXTreeTable getTable() { if (table == null) { if (model == null) { model = new HttpFuzzTableModel(); }/*from w w w . j a v a2 s.c o m*/ table = new JXTreeTable(model); table.setDoubleBuffered(true); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setName("HttpFuzzResultTable"); table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12)); table.setDefaultRenderer(Pair.class, new IconTableCellRenderer()); int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 }; for (int i = 0, count = widths.length; i < count; i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } @Override public void mouseReleased(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) { if (e.isPopupTrigger()) { if (e.isPopupTrigger()) { // Select list item on right click JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.changeSelection(row, 0, false, false); } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } } }); table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() { @Override public void valueChanged(javax.swing.event.ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (table.getSelectedRowCount() == 0) { return; } final int row = table.getSelectedRow(); if (getEntry(row) instanceof HttpFuzzRequestRecord) { final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row)) .getHistory(); try { getMessageInspection().setMessage(historyReference.getHttpMessage()); } catch (HttpMalformedHeaderException | SQLException ex) { logger.error(ex.getMessage(), ex); } } updateValues(); redrawDiagrams(); } } }); } table.getTableHeader().addMouseListener(new MouseListener() { int sortedOn = -1; @Override public void mouseReleased(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent e) { int index = table.columnAtPoint(e.getPoint()); List<HttpFuzzRecord> list = model.getEntries(); if (list.size() == 0) { return; } HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator(); comp.setFeature(index); if (index == sortedOn) { Collections.sort(list, comp); Collections.reverse(list); sortedOn = -1; } else { Collections.sort(list, comp); sortedOn = index; } table.updateUI(); } }); table.setRootVisible(false); table.setVisible(true); return table; }
From source file:com.vgi.mafscaling.OpenLoop.java
private void createRunTables(JPanel dataRunPanel) { GridBagConstraints gbc_run = new GridBagConstraints(); gbc_run.anchor = GridBagConstraints.PAGE_START; gbc_run.insets = new Insets(0, 2, 0, 2); for (int i = 0; i < RunCount; ++i) { runTables[i] = new JTable(); JTable table = runTables[i]; table.getTableHeader().setReorderingAllowed(false); table.setModel(new DefaultTableModel(RunRowsCount, 3)); table.setColumnSelectionAllowed(true); table.setCellSelectionEnabled(true); table.setBorder(new LineBorder(new Color(0, 0, 0))); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getColumnModel().getColumn(0) .setHeaderValue("<html><center>Engine<br>Speed<br>(RPM)<br></center></html>"); table.getColumnModel().getColumn(1) .setHeaderValue("<html><center>MAF<br>Sensor<br>Voltage<br></center></html>"); table.getColumnModel().getColumn(2) .setHeaderValue("<html><center>AFR<br>Error<br>%<br></center></html>"); Utils.initializeTable(table, ColumnWidth); excelAdapter.addTable(table, true, false); gbc_run.gridx = i;/*from ww w . j a v a 2 s . co m*/ gbc_run.gridy = 0; dataRunPanel.add(table.getTableHeader(), gbc_run); gbc_run.gridy = 1; dataRunPanel.add(table, gbc_run); } }
From source file:com.puzzle.gui.MainFrame.java
/** * table?//from w w w . ja v a2 s. c om * * @param table */ public static void makeJtableFace(javax.swing.JTable table) { try { DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() { public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (row % 2 == 0) { setBackground(java.awt.Color.white); // } else if (row % 2 == 1) { setBackground(new java.awt.Color(206, 231, 255)); //? } return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } }; for (int i = 0; i < table.getColumnCount(); i++) { table.getColumn(table.getColumnName(i)).setCellRenderer(tcr); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:net.pandoragames.far.ui.swing.FileListPanel.java
private void init(SwingConfig config, ComponentRepository componentRepository) { this.setLayout(new BorderLayout()); this.setBorder( BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); tableModel = componentRepository.getTableModel(); componentRepository.getResetDispatcher().addResetable(tableModel); componentRepository.getSearchBaseListener().addResetable(tableModel); componentRepository.getUndoListener().setTableModel(tableModel); JTable fileListTable = componentRepository.getFileSetTable(); int totalWidth = fileListTable.getPreferredSize().width; fileListTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); fileListTable.setColumnSelectionAllowed(true); fileListTable.getTableHeader().addMouseListener(new TableHeaderMouseListener()); fileListTable.getTableHeader().getColumnModel().getColumn(0) .setHeaderRenderer(new TableHeaderCheckBoxColumnRenderer()); fileListPopupMenu = new FileListPopupMenu(fileListTable, tableModel, componentRepository, config); fileListTable.setComponentPopupMenu(fileListPopupMenu); fileListTable.addMouseListener(new FileViewOpener(fileListTable, componentRepository.getRootWindow(), config, componentRepository)); fileListTable.getColumnModel().getColumn(0).setPreferredWidth(20); fileListTable.getColumnModel().getColumn(0).setMaxWidth(20); fileListTable.getColumnModel().getColumn(1).setCellRenderer(new TargetFileListTableCellRenderer()); fileListTable.getColumnModel().getColumn(1).setPreferredWidth(2 * totalWidth / 5); fileListTable.getColumnModel().getColumn(2).setCellRenderer(new PathColumnRenderer()); fileListTable.getColumnModel().getColumn(3).setCellRenderer(new InfoColumnRenderer(config)); JScrollPane scrollPane = new JScrollPane(fileListTable); this.add(scrollPane, BorderLayout.CENTER); SelectCounter fileCounter = new SelectCounter(); fileCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); fileCounter.setForeground(Color.GRAY); ErrorCounter errorCounter = new ErrorCounter(); errorCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); JPanel counterLine = new JPanel(); counterLine.setLayout(new BorderLayout()); counterLine.add(fileCounter, BorderLayout.WEST); counterLine.add(errorCounter, BorderLayout.EAST); JProgressBar progressBar = new JProgressBar(); progressBar.setEnabled(false);/* w w w .j a v a 2 s . c o m*/ progressBar.setMaximumSize(new Dimension(100, 20)); progressBar.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); componentRepository.getProgressBarUpdater().setProgressBar(progressBar); JPanel progressBarPanel = new JPanel(); progressBarPanel.add(progressBar); counterLine.add(progressBarPanel, BorderLayout.CENTER); counterLine.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); this.add(counterLine, BorderLayout.SOUTH); tableModel.addTableModelListener(new ColumnCountListener(fileCounter)); tableModel.addTableModelListener(errorCounter); componentRepository.getResetDispatcher().addResetable(fileCounter); componentRepository.getSearchBaseListener().addResetable(fileCounter); componentRepository.getOperationCallBackListener().addComponentStartReseted(fileCounter, OperationType.FIND); componentRepository.getResetDispatcher().addResetable(errorCounter); componentRepository.getSearchBaseListener().addResetable(errorCounter); viewAction = new ActionView(componentRepository, config); }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java
private void addTable() { defaultTableModel.addColumn(""); defaultTableModel.addColumn("Property"); defaultTableModel.addColumn("Value"); final LegendColourRenderer cellRenderer = new LegendColourRenderer(); final JTable table = new JTable(defaultTableModel) { @Override/*w ww.jav a2 s . co m*/ public TableCellRenderer getCellRenderer(int row, int column) { if (column == 0) { return cellRenderer; } return super.getCellRenderer(row, column); } @Override public boolean isCellEditable(int row, int column) { return false; }; }; table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getFirstIndex() >= 0) { String value = (String) defaultTableModel.getValueAt(table.getSelectedRow(), 1); eventTablePanel.setFilterString(value); } } }); TableColumn column; for (int i = 0; i < 3; i++) { column = table.getColumnModel().getColumn(i); switch (i) { case 0: column.setMinWidth(15); column.setMaxWidth(15); column.setPreferredWidth(15); break; case 2: column.setMinWidth(70); column.setMaxWidth(70); column.setPreferredWidth(70); break; } } JScrollPane tablecrollPane = new JScrollPane(table); tablecrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); this.add(tablecrollPane, BorderLayout.CENTER); }
From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidBatchScaleImporter.java
private void initExportNameValidator() { table.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(new JTextField()) { @Override/*from w w w . ja v a2s . c om*/ public boolean stopCellEditing() { boolean result = super.stopCellEditing(); if (!result) { return false; } String value = (String) getCellEditorValue(); value = value.trim(); if ((StringUtils.isNotEmpty(value) && value.matches("[a-z0-9_.]*"))) { return super.stopCellEditing(); } ((JComponent) this.getComponent()).setBorder(new LineBorder(JBColor.RED)); return false; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { ((JComponent) this.getComponent()).setBorder(table.getBorder()); return super.getTableCellEditorComponent(table, value, isSelected, row, column); } }); }
From source file:fll.subjective.SubjectiveFrame.java
private void createSubjectiveTable(final JTabbedPane tabbedPane, final ScoreCategory subjectiveCategory) { final SubjectiveTableModel tableModel = new SubjectiveTableModel(_scoreDocument, subjectiveCategory, _schedule, _scheduleColumnMappings); final JTable table = new JTable(tableModel); table.setDefaultRenderer(Date.class, DateRenderer.INSTANCE); // Make grid lines black (needed for Mac) table.setGridColor(Color.BLACK); // auto table sorter table.setAutoCreateRowSorter(true);/*from w w w. j a v a 2 s . com*/ final String title = subjectiveCategory.getTitle(); _tables.put(title, table); final JScrollPane tableScroller = new JScrollPane(table); tableScroller.setPreferredSize(new Dimension(640, 480)); tabbedPane.addTab(title, tableScroller); table.setSelectionBackground(Color.YELLOW); setupTabReturnBehavior(table); int goalIndex = 0; for (final AbstractGoal goal : subjectiveCategory.getGoals()) { final TableColumn column = table.getColumnModel() .getColumn(goalIndex + tableModel.getNumColumnsLeftOfScores()); if (goal.isEnumerated()) { final Vector<String> posValues = new Vector<String>(); posValues.add(""); for (final EnumeratedValue posValue : goal.getSortedValues()) { posValues.add(posValue.getTitle()); } column.setCellEditor(new DefaultCellEditor(new JComboBox<String>(posValues))); } else { final JTextField editor = new SelectTextField(); column.setCellEditor(new DefaultCellEditor(editor)); } ++goalIndex; } }
From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java
private static JTable createTable(TableModel m) { JTable t = new JTable(m) { @Override/* ww w.j a v a 2s. c o m*/ public String getToolTipText(MouseEvent event) { JTable t = (JTable) event.getSource(); int x = t.rowAtPoint(event.getPoint()); if (x == -1) return null; int y = t.columnAtPoint(event.getPoint()); if (y == -1) return null; Object o = t.getValueAt(x, y); if (o == null) return null; return String.valueOf(o); } }; t.setToolTipText(""); t.setShowVerticalLines(false); DefaultTableCellRenderer render = new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (!isSelected && !hasFocus) this.setBackground(row % 2 == 0 ? color1 : color2); if (value != null && value instanceof Boolean) { if (Boolean.TRUE.equals(value)) this.setText("\u2612"); else if (Boolean.FALSE.equals(value)) this.setText(""); } return c; } }; render.setOpaque(true); for (int i = 0; i < t.getColumnModel().getColumnCount(); ++i) { t.getColumnModel().getColumn(i).setCellRenderer(render); } return t; }
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
private void updateDetailsColumnModel(JTable table) { if (table != null) { // Install cell editor for editing file name if (!readOnly && (table.getColumnCount() > COLUMN_FILENAME)) { table.getColumnModel().getColumn(COLUMN_FILENAME).setCellEditor(getDetailsTableCellEditor()); }/*from www . j a va 2s . co m*/ } }