List of usage examples for javax.swing JTable setSelectionBackground
@BeanProperty(description = "A default background color for selected cells.") public void setSelectionBackground(Color selectionBackground)
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 www.j ava 2 s.c o m 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:marytts.tools.redstart.AdminWindow.java
private void buildPromptTable() { this.promptArray = this.currentSession.getPromptArray(); System.out.println("Loading prompts..."); Test.output("Array contains " + promptArray.length + " prompts."); // Make column names array String[] columnNames = new String[3]; columnNames[REC_STATUS_COLUMN] = "Status"; columnNames[BASENAME_COLUMN] = "Basename"; columnNames[PROMPT_TEXT_COLUMN] = "Prompt Preview"; // Now create the table itself JTable table = new JTable(new PromptTableModel(promptArray, columnNames, redAlertMode)); table.setColumnSelectionAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Set alignment for the status colum to centered DefaultTableCellRenderer renderer = new ClippingColorRenderer(); renderer.setHorizontalAlignment(JTextField.CENTER); table.getColumnModel().getColumn(REC_STATUS_COLUMN).setCellRenderer(renderer); // Set selection highlight colour to light blue table.setSelectionBackground(new java.awt.Color(153, 204, 255)); // Add listeners table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { displayPromptText();//from w ww. j a v a2s .co m } }); // Store the table in an instance field accessible to the entire class this.jTable_PromptSet = table; Thread recordingStatusInitialiser = new Thread() { public void run() { updateAllRecStatus(); } }; recordingStatusInitialiser.start(); // Display table in the appropriate component pane jScrollPane_PromptSet.setViewportView(table); if (promptArray.length > 0) { table.setRowSelectionInterval(0, 0); // Show first row of prompt table as selected displayPromptText(); // Display the prompt text for the first prompt in the prompt display pane } setColumnWidths(); System.out.println("Total " + table.getRowCount() + " prompts loaded."); }
From source file:jp.massbank.spectrumsearch.SearchPage.java
/** * ??//w w w.j a v a 2s. c om */ private void updateSelectQueryTable(JTable tbl) { // ? this.setCursor(waitCursor); int selRow = tbl.getSelectedRow(); if (selRow >= 0) { tbl.clearSelection(); Color defColor = tbl.getSelectionBackground(); tbl.setRowSelectionInterval(selRow, selRow); tbl.setSelectionBackground(Color.PINK); tbl.update(tbl.getGraphics()); tbl.setSelectionBackground(defColor); } // ? this.setCursor(Cursor.getDefaultCursor()); }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
private JTable createTable(final ViewState state) { JTable table; final ModelGraph selected = state.getSelected(); if (selected != null) { final Vector<Vector<String>> rows = new Vector<Vector<String>>(); ConcurrentHashMap<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>(); Metadata staticMet = selected.getModel().getStaticMetadata(); Metadata inheritedMet = selected.getInheritedStaticMetadata(state); Metadata completeMet = new Metadata(); if (staticMet != null) { completeMet.replaceMetadata(staticMet.getSubMetadata(state.getCurrentMetGroup())); }//from w w w. j a v a2 s .c o m if (selected.getModel().getExtendsConfig() != null) { for (String configGroup : selected.getModel().getExtendsConfig()) { Metadata extendsMetadata = state.getGlobalConfigGroups().get(configGroup).getMetadata() .getSubMetadata(state.getCurrentMetGroup()); for (String key : extendsMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, configGroup); completeMet.replaceMetadata(key, extendsMetadata.getAllMetadata(key)); } } } } if (inheritedMet != null) { Metadata inheritedMetadata = inheritedMet.getSubMetadata(state.getCurrentMetGroup()); for (String key : inheritedMetadata.getAllKeys()) { if (!completeMet.containsKey(key)) { keyToGroupMap.put(key, "__inherited__"); completeMet.replaceMetadata(key, inheritedMetadata.getAllMetadata(key)); } } } List<String> keys = completeMet.getAllKeys(); Collections.sort(keys); for (String key : keys) { if (key.endsWith("/envReplace")) { continue; } String values = StringUtils.join(completeMet.getAllMetadata(key), ","); Vector<String> row = new Vector<String>(); row.add(keyToGroupMap.get(key)); row.add(key); row.add(values); row.add(Boolean.toString(Boolean.parseBoolean(completeMet.getMetadata(key + "/envReplace")))); rows.add(row); } table = new JTable();// rows, new Vector<String>(Arrays.asList(new // String[] { "key", "values", "envReplace" }))); table.setModel(new AbstractTableModel() { public String getColumnName(int col) { switch (col) { case 0: return "group"; case 1: return "key"; case 2: return "values"; case 3: return "envReplace"; default: return null; } } public int getRowCount() { return rows.size() + 1; } public int getColumnCount() { return 4; } public Object getValueAt(int row, int col) { if (row >= rows.size()) { return null; } String value = rows.get(row).get(col); if (value == null && col == 3) { return "false"; } if (value == null && col == 0) { return "__local__"; } return value; } public boolean isCellEditable(int row, int col) { if (row >= rows.size()) { return selected.getModel().getStaticMetadata().containsGroup(state.getCurrentMetGroup()); } if (col == 0) { return false; } String key = rows.get(row).get(1); return key == null || (selected.getModel().getStaticMetadata() != null && selected.getModel().getStaticMetadata().containsKey(getKey(key, state))); } public void setValueAt(Object value, int row, int col) { if (row >= rows.size()) { Vector<String> newRow = new Vector<String>( Arrays.asList(new String[] { null, null, null, null })); newRow.add(col, (String) value); rows.add(newRow); } else { Vector<String> rowValues = rows.get(row); rowValues.add(col, (String) value); rowValues.remove(col + 1); } this.fireTableCellUpdated(row, col); } }); MyTableListener tableListener = new MyTableListener(state); table.getModel().addTableModelListener(tableListener); table.getSelectionModel().addListSelectionListener(tableListener); } else { table = new JTable(new Vector<Vector<String>>(), new Vector<String>(Arrays.asList(new String[] { "key", "values", "envReplace" }))); } // table.setFillsViewportHeight(true); table.setSelectionBackground(Color.cyan); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableCellRenderer cellRenderer = new TableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel field = new JLabel((String) value); if (column == 0) { field.setForeground(Color.gray); } else { if (isSelected) { field.setBorder(new EtchedBorder(1)); } if (table.isCellEditable(row, 1)) { field.setForeground(Color.black); } else { field.setForeground(Color.gray); } } return field; } }; TableColumn groupCol = table.getColumnModel().getColumn(0); groupCol.setPreferredWidth(75); groupCol.setCellRenderer(cellRenderer); TableColumn keyCol = table.getColumnModel().getColumn(1); keyCol.setPreferredWidth(200); keyCol.setCellRenderer(cellRenderer); TableColumn valuesCol = table.getColumnModel().getColumn(2); valuesCol.setPreferredWidth(300); valuesCol.setCellRenderer(cellRenderer); TableColumn envReplaceCol = table.getColumnModel().getColumn(3); envReplaceCol.setPreferredWidth(75); envReplaceCol.setCellRenderer(cellRenderer); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3 && DefaultPropView.this.table.getSelectedRow() != -1) { int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition()); String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state); Metadata staticMet = state.getSelected().getModel().getStaticMetadata(); override.setVisible(staticMet == null || !staticMet.containsKey(key)); delete.setVisible(staticMet != null && staticMet.containsKey(key)); tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY()); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); return table; }