List of usage examples for javax.swing JTable setShowGrid
@BeanProperty(description = "The color used to draw the grid lines.") public void setShowGrid(boolean showGrid)
From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
/** * Setup the JTable with its desired characteristics *//*from www . ja va 2 s .c o m*/ private void setupTable() { table = new CustomTable(spreadsheetModel); table.setShowGrid(true); table.setGridColor(Color.BLACK); table.setShowVerticalLines(true); table.setShowHorizontalLines(true); table.setGridColor(UIHelper.LIGHT_GREEN_COLOR); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(true); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getSelectionModel().addListSelectionListener(this); table.getColumnModel().getSelectionModel().addListSelectionListener(this); table.getTableHeader().setReorderingAllowed(true); table.getColumnModel().addColumnModelListener(this); try { table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer()); } catch (ClassNotFoundException e) { // ignore this error } table.addMouseListener(this); table.getTableHeader().addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent event) { } public void mouseMoved(MouseEvent event) { // display a tooltip when user hovers over a column. tooltip is derived // from the description of a field from the TableReferenceObject. JTable table = ((JTableHeader) event.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int colIndex = colModel.getColumnIndexAtX(event.getX()); // greater than 1 to account for the row no. being the first col if (colIndex >= 1) { TableColumn tc = colModel.getColumn(colIndex); if (tc != null) { try { table.getTableHeader().setToolTipText(getFieldDescription(tc)); } catch (Exception e) { // ignore this error } } } } }); //table.getColumnModel().addColumnModelListener(this); InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = table.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // maintain previous tab action procedure previousTabAction.actionPerformed(e); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; table.getActionMap().put(im.get(tab), newTabAction); TableColumnModel model = table.getColumnModel(); String previousColumnName = null; for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) { if (!model.getColumn(columnIndex).getHeaderValue().toString() .equals(TableReferenceObject.ROW_NO_TEXT)) { model.getColumn(columnIndex).setHeaderRenderer(columnRenderer); model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString())); // add appropriate cell editor for cell. spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName); previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString(); } else { model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer()); } } JTableHeader header = table.getTableHeader(); header.setBackground(UIHelper.BG_COLOR); header.addMouseListener(new HeaderListener(header, columnRenderer)); table.addNotify(); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ChannelAcquisitionComponent.java
/** * Sets the plane info for the specified channel. * /*from w w w. j a va 2 s . c o m*/ * @param index The index of the channel. */ void setPlaneInfo(int index) { if (channel.getIndex() != index) return; Collection result = model.getChannelPlaneInfo(index); String[][] values = new String[2][result.size() + 1]; String[] names = new String[result.size() + 1]; int i = 0; Iterator j = result.iterator(); PlaneInfo info; Map<String, Object> details; List<String> notSet; names[0] = "t"; values[0][i] = "Delta T"; values[1][i] = "Exposure"; i++; while (j.hasNext()) { info = (PlaneInfo) j.next(); details = EditorUtil.transformPlaneInfo(info); notSet = (List<String>) details.get(EditorUtil.NOT_SET); if (!notSet.contains(EditorUtil.DELTA_T)) { if (details.get(EditorUtil.DELTA_T) instanceof BigResult) { MetadataViewerAgent.logBigResultExeption(this, details.get(EditorUtil.DELTA_T), EditorUtil.DELTA_T); values[0][i] = "N/A"; } else { double tInS = ((Double) details.get(EditorUtil.DELTA_T)); values[0][i] = getReadableTime(tInS); } } else values[0][i] = "--"; if (!notSet.contains(EditorUtil.EXPOSURE_TIME)) { if (details.get(EditorUtil.EXPOSURE_TIME) instanceof BigResult) { MetadataViewerAgent.logBigResultExeption(this, details.get(EditorUtil.EXPOSURE_TIME), EditorUtil.EXPOSURE_TIME); values[1][i] = "N/A"; } else { double tInS = ((Double) details.get(EditorUtil.EXPOSURE_TIME)); values[1][i] = getReadableTime(tInS); } } else values[1][i] = "--"; names[i] = "t=" + i; i++; } if (i > 1) { JTable table = new JTable(values, names); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setShowGrid(true); table.setGridColor(Color.LIGHT_GRAY); JScrollPane pane = new JScrollPane(table); Dimension d = table.getPreferredSize(); Dimension de = exposureTask.getPreferredSize(); pane.setPreferredSize(new Dimension(de.width - 10, 4 * d.height)); exposureTask.add(pane); exposureTask.setVisible(true); } else { exposureTask.setVisible(false); } }
From source file:org.revager.tools.GUITools.java
/** * Creates a new standard table./*from w w w. j av a2 s. co m*/ * * @param model * the table model * @param showHeader * true if the header of the table should be visible * * @return the newly created table */ @SuppressWarnings("serial") public static JTable newStandardTable(TableModel model, boolean showHeader) { /* * Prep. for rollover */ if (lastRolloverKey == Integer.MAX_VALUE) { lastRolloverKey = 0; } else { lastRolloverKey++; } final int keyIdx = lastRolloverKey; rollOverRowIndex.put(keyIdx, -1); final JTable table = new JTable(model) { @Override public boolean editCellAt(int row, int column, java.util.EventObject e) { boolean result = super.editCellAt(row, column, e); final Component editor = getEditorComponent(); TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer(); Font cellFont = null; if (renderer instanceof DefaultTableCellRenderer) { cellFont = ((DefaultTableCellRenderer) renderer).getFont(); } if (editor != null && editor instanceof JTextComponent) { JTextComponent jTextComponent = (JTextComponent) editor; if (e == null) { jTextComponent.selectAll(); } else { SwingUtilities.invokeLater(jTextComponent::selectAll); } jTextComponent.setBorder(UI.MARKED_BORDER_INLINE); if (cellFont != null) { jTextComponent.setFont(cellFont); } editor.requestFocusInWindow(); } return result; } @Override public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof DefaultTableCellRenderer) { ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3)); } return renderer; } @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { Component comp = super.prepareRenderer(renderer, row, col); // Rollover comp.setBackground(getBackground()); comp = super.prepareRenderer(renderer, row, col); if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) { comp.setForeground(getForeground()); comp.setBackground(UI.BLUE_BACKGROUND_COLOR); } // Tooltips JComponent jcomp = (JComponent) comp; if (renderer instanceof DefaultTableCellRenderer) { String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText(); if (!StringUtils.isEmpty(toolTip)) { jcomp.setToolTipText(toolTip); } } return comp; } }; // Table properties table.setRowHeight(UI.TABLE_ROW_HEIGHT); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowGrid(false); table.setShowHorizontalLines(true); table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // Rollover MouseInputAdapter rolloverListener = new MouseInputAdapter() { @Override public void mouseExited(MouseEvent e) { rollOverRowIndex.put(keyIdx, -1); table.repaint(); } @Override public void mouseMoved(MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (row != rollOverRowIndex.get(keyIdx)) { rollOverRowIndex.put(keyIdx, row); table.repaint(); } } }; table.addMouseMotionListener(rolloverListener); table.addMouseListener(rolloverListener); // Header if (!showHeader) { table.setTableHeader(null); } return table; }
From source file:uk.ac.ebi.demo.picr.swing.PICRBLASTDemo.java
public PICRBLASTDemo() { //set general layout setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); add(Box.createVerticalStrut(5)); //create components JPanel row1 = new JPanel(); row1.setLayout(new BoxLayout(row1, BoxLayout.X_AXIS)); row1.add(Box.createHorizontalStrut(5)); row1.setBorder(BorderFactory.createTitledBorder("")); row1.add(new JLabel("Fragment:")); row1.add(Box.createHorizontalStrut(10)); final JTextArea sequenceArea = new JTextArea(5, 40); sequenceArea.setMaximumSize(sequenceArea.getPreferredSize()); row1.add(Box.createHorizontalStrut(10)); row1.add(sequenceArea);//w ww . ja va 2s . c o m row1.add(Box.createHorizontalGlue()); JPanel row2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); row2.setBorder(BorderFactory.createTitledBorder("Target Databases")); final JList databaseList = new JList(); JScrollPane listScroller = new JScrollPane(databaseList); listScroller.setMaximumSize(new Dimension(100, 10)); JButton loadDBButton = new JButton("Load Databases"); row2.add(listScroller); row2.add(loadDBButton); JPanel row3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); JCheckBox onlyActiveCheckBox = new JCheckBox("Only Active"); onlyActiveCheckBox.setSelected(true); row3.add(new JLabel("Options: ")); row3.add(onlyActiveCheckBox); add(row1); add(row2); add(row3); final String[] columns = new String[] { "Database", "Accession", "Version", "Taxon ID" }; final JTable dataTable = new JTable(new Object[0][0], columns); dataTable.setShowGrid(true); add(new JScrollPane(dataTable)); JPanel buttonPanel = new JPanel(); JButton mapAccessionButton = new JButton("Generate Mapping!"); buttonPanel.add(mapAccessionButton); add(buttonPanel); //create listeners! //update boolean flag in communication class onlyActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { client.setOnlyActive(((JCheckBox) e.getSource()).isSelected()); } }); //performs mapping call and updates interface with results mapAccessionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (!"".equals(sequenceArea.getText())) { //TODO filters and database are hardcoded here. They should be added to the input panel at a later revision. java.util.List<UPEntry> entries = client.performBlastMapping(sequenceArea.getText(), databaseList.getSelectedValues(), "90", "", "IDENTITY", "UniprotKB", "", false, new BlastParameter()); //compute size of array if (entries != null) { int size = 0; for (UPEntry entry : entries) { for (CrossReference xref : entry.getIdenticalCrossReferences()) { size++; } for (CrossReference xref : entry.getLogicalCrossReferences()) { size++; } } if (size > 0) { final Object[][] data = new Object[size][4]; int i = 0; for (UPEntry entry : entries) { for (CrossReference xref : entry.getIdenticalCrossReferences()) { data[i][0] = xref.getDatabaseName(); data[i][1] = xref.getAccession(); data[i][2] = xref.getAccessionVersion(); data[i][3] = xref.getTaxonId(); i++; } for (CrossReference xref : entry.getLogicalCrossReferences()) { data[i][0] = xref.getDatabaseName(); data[i][1] = xref.getAccession(); data[i][2] = xref.getAccessionVersion(); data[i][3] = xref.getTaxonId(); i++; } } //refresh DefaultTableModel dataModel = new DefaultTableModel(); dataModel.setDataVector(data, columns); dataTable.setModel(dataModel); System.out.println("update done"); } else { JOptionPane.showMessageDialog(null, "No Mappind data found."); } } else { JOptionPane.showMessageDialog(null, "No Mappind data found."); } } else { JOptionPane.showMessageDialog(null, "You must enter a valid FASTA sequence to map."); } } catch (SOAPFaultException soapEx) { JOptionPane.showMessageDialog(null, "A SOAP Error occurred."); soapEx.printStackTrace(); } } }); //loads list of mapping databases from communication class loadDBButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { java.util.List<String> databases = client.loadDatabases(); if (databases != null && databases.size() > 0) { databaseList.setListData(databases.toArray()); System.out.println("database refresh done"); } else { JOptionPane.showMessageDialog(null, "No Databases Loaded!."); } } catch (SOAPFaultException soapEx) { JOptionPane.showMessageDialog(null, "A SOAP Error occurred."); soapEx.printStackTrace(); } } }); }
From source file:VGL.SummaryChartUI.java
private void updateDisplay() { //find out which buttons have been selected ArrayList<Integer> selectedTraits = new ArrayList<Integer>(); for (int i = 0; i < manager.getTraitSet().length; i++) { if (traitCheckBoxes[i].isSelected()) { selectedTraits.add(i);// www.jav a 2 s .co m } } PhenotypeCount[] result = manager.calculateTotals(selectedTraits, sexCheckBox.isSelected()); String[] columnHeadings = { Messages.getInstance().getString("VGLII.Phenotype"), Messages.getInstance().getString("VGLII.Observed"), Messages.getInstance().getString("VGLII.Expected") }; data = new Object[result.length][3]; for (int i = 0; i < result.length; i++) { data[i][0] = Messages.getInstance().translateLongPhenotypeName(result[i].getPhenotype()); data[i][1] = result[i].getCount(); data[i][2] = ""; } //if none selected, the "phenotype" is "organism" if ((selectedTraits.size() == 0) && !sexCheckBox.isSelected()) data[0][0] = Messages.getInstance().getString("VGLII.Organism"); // set width of columns sensibly - find longest one int maxPhenoStringLength = 0; for (int i = 0; i < result.length; i++) { if (data[i][0].toString().length() > maxPhenoStringLength) maxPhenoStringLength = data[i][0].toString().length(); } int phenoStringWidth = maxPhenoStringLength * 8; JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JTable table = new JTable(new SummaryDataTableModel(data, columnHeadings)) { //Implement table header tool tips. protected JTableHeader createDefaultTableHeader() { return new JTableHeader(columnModel) { public String getToolTipText(MouseEvent e) { String tip = null; java.awt.Point p = e.getPoint(); int index = columnModel.getColumnIndexAtX(p.x); int realIndex = columnModel.getColumn(index).getModelIndex(); return columnToolTips[realIndex]; } }; } }; table.setGridColor(Color.BLACK); table.setShowGrid(true); table.getColumnModel().getColumn(0).setPreferredWidth(phenoStringWidth); table.getModel().addTableModelListener(this); panel.add(table.getTableHeader()); panel.add(table); resultPanel.removeAll(); resultPanel.add(panel); resultPanel.revalidate(); repaint(); }