List of usage examples for javax.swing JTable columnAtPoint
public int columnAtPoint(Point point)
point
lies in, or -1 if the result is not in the range [0, getColumnCount()
-1]. From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java
private static JTable createTable(TableModel m) { JTable t = new JTable(m) { @Override/*from w ww .ja va 2s . co 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.choicemaker.cm.modelmaker.gui.panels.HoldVsAccuracyPlotPanel.java
private void buildPanel() { XYSeriesCollection dataset = new XYSeriesCollection(); String title = ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.title"); data = new XYSeries(title); dataset.addSeries(data);//from w w w . j a v a2s. c om final PlotOrientation orientation = PlotOrientation.VERTICAL; chart = ChartFactory.createXYLineChart(title, ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.cm.accuracy"), ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.holdpercentage"), dataset, orientation, true, true, true); MouseListener tableMouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { Point origin = e.getPoint(); JTable src = (JTable) e.getSource(); int row = src.rowAtPoint(origin); int col = src.columnAtPoint(origin); ModelMaker mm = parent.getModelMaker(); if (src == accuracyTable) { if (col < 2) { if (!Float.isNaN(accuracyData[row][2]) && !Float.isNaN(accuracyData[row][3])) mm.setThresholds(new Thresholds(accuracyData[row][2], accuracyData[row][3])); } else if (col == 2) { if (!Float.isNaN(accuracyData[row][2])) mm.setDifferThreshold(accuracyData[row][2]); } else { if (!Float.isNaN(accuracyData[row][3])) mm.setMatchThreshold(accuracyData[row][3]); } } else { if (col < 2) { if (!Float.isNaN(hrData[row][2]) && !Float.isNaN(hrData[row][3])) mm.setThresholds(new Thresholds(hrData[row][2], hrData[row][3])); } else if (col == 2) { if (!Float.isNaN(hrData[row][2])) mm.setDifferThreshold(hrData[row][2]); } else { if (!Float.isNaN(hrData[row][3])) mm.setMatchThreshold(hrData[row][3]); } } } }; chart.setBackgroundPaint(getBackground()); accuracyTable = new AccuracyTable(true, accuracies); accuracyTable.addMouseListener(tableMouseListener); accuracyPanel = getPanel(accuracyTable, ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.hrvsacc")); hrTable = new AccuracyTable(false, hrs); hrTable.addMouseListener(tableMouseListener); hrPanel = getPanel(hrTable, ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.accvshr")); accuracyTable.setEnabled(false); hrTable.setEnabled(false); }
From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java
private MouseAdapter treatmentCategorizationListener(final NetworkRelativeEffectTableCellRenderer renderer) { return new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { JTable table = (JTable) e.getComponent(); int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint())); int col = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint())); if (col == row) { Treatment treatment = renderer.getTreatment(table.getModel(), col); TreatmentDefinition treatmentDefinition = d_pm.getTreatmentDefinition(treatment); Category category = treatmentDefinition.getContents().first(); if (category != null && !category.isTrivial()) { d_mainWindow.leftTreeFocus(category.getCategorization()); }//w w w .ja v a 2 s . c o m } } } }; }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java
private void setControlDefaults() { String[] colName = { "Delays (ps)" }; int max = 16666; try {/*ww w.j av a2 s .com*/ max = Integer.parseInt(core_.getProperty("Laser", "Frequency")); } catch (Exception e) { } tableModel_ = new DelayTableModel(colName, (sap_.getDelaysArray()).get(0), 0, max, 25); tableModel_.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { sap_.setDelaysArray(0, tableModel_.getData()); fm_.setGatingData((sap_.getDelaysArray()).get(0)); var_.delays = tableModel_.getData(); } }); delayTable_ = new JTable() { @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component comp = super.prepareRenderer(renderer, row, column); int modelRow = convertRowIndexToModel(row); int modelColumn = convertColumnIndexToModel(column); if (modelColumn != 0 && modelRow != 0) { comp.setBackground(Color.GREEN); } return comp; } }; delayTable_.setModel(tableModel_); delayTable_.setSurrendersFocusOnKeystroke(true); delayTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); JScrollPane scroller = new javax.swing.JScrollPane(delayTable_); delayTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(60, 100)); delayTablePanel.setLayout(new BorderLayout()); delayTablePanel.add(scroller, BorderLayout.CENTER); final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete delay"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = delayTable_.getSelectedRow(); tableModel_.removeRow(r); } }); JMenuItem addItem = new JMenuItem("Add delay"); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = delayTable_.getSelectedRow(); tableModel_.insertRow(r + 1, 0); } }); popupMenu.add(addItem); popupMenu.add(deleteItem); delayTable_.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { // System.out.println("pressed"); } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable) e.getSource(); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); if (!source.isRowSelected(row)) source.changeSelection(row, column, false, false); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); // Set up slider controls mcpSlider_ = new SliderControl("MCP voltage (V)", 300, 850, 750); mcpVoltagePanel.setLayout(new BorderLayout()); mcpVoltagePanel.add(mcpSlider_, BorderLayout.SOUTH); mcpSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { mcpSliderPropertyChange(evt); } }); gatewidthSlider_ = new SliderControl("Gate width (ps)", 200, 7000, 3000); gatewidthPanel.setLayout(new BorderLayout()); gatewidthPanel.add(gatewidthSlider_, BorderLayout.SOUTH); gatewidthSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { gatewidthSliderPropertyChange(evt); } }); HRIControlsPanel.revalidate(); HRIControlsPanel.repaint(); slowDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0); slowCurrentDelayPanel.setLayout(new BorderLayout()); slowCurrentDelayPanel.add(slowDelaySlider_, BorderLayout.SOUTH); slowDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { slowDelaySlider_.setValue(tableModel_.validateData(slowDelaySlider_.getValue().intValue())); slowDelaySliderPropertyChange(evt); } }); fastDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0); fastCurrentDelayPanel.setLayout(new BorderLayout()); fastCurrentDelayPanel.add(fastDelaySlider_, BorderLayout.SOUTH); fastDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() { @Override public void propertyChange(java.beans.PropertyChangeEvent evt) { fastDelaySlider_.setValue(tableModel_.validateData(fastDelaySlider_.getValue().intValue())); fastDelaySliderPropertyChange(evt); } }); delayBoxTabbedPane.revalidate(); delayBoxTabbedPane.repaint(); fm_ = new FindMaxpoint(); maxpointGraphPanel.setLayout(new BorderLayout()); chartPanel_ = new ChartPanel(fm_.getChart()); maxpointGraphPanel.add(chartPanel_, BorderLayout.NORTH); // for some reason maxpointGraphPanel's height and width are returned 0 // so hardcode for now... chartPanel_.setMaximumDrawWidth(500); chartPanel_.setMaximumDrawHeight(200); chartPanel_.setPreferredSize(new Dimension(500, 200)); // Set values for other controls based on underlying data to ensure // that all controls are in a consistent state. scanDelCheck.setSelected(sap_.getUseScanFLIM()); }
From source file:gdt.jgui.tool.JEntityEditor.java
private void showElement(Sack entity, String element$) { try {//from ww w . ja v a2 s .c om // System.out.println("EntityEditor:showElement:"+element$); Core[] ca = null; if ("attributes".equals(element$)) ca = entity.attributesGet(); else ca = entity.elementGet(element$); final JTable table = new JTable(); DefaultTableModel model = new DefaultTableModel(null, new String[] { "type", "name", "value" }); table.setModel(model); table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer()); table.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(e.getPoint()); String name = table.getColumnName(col); // System.out.println("Column index selected " + col + " " + name); sort(name); } }); JScrollPane scrollPane = new JScrollPane(); tabbedPane.add(element$, scrollPane); scrollPane.add(table); scrollPane.setViewportView(table); if (ca != null) for (Core aCa : ca) { model.addRow(new String[] { aCa.type, aCa.name, aCa.value }); } } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initTablePopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteMenuItem = new JMenuItem("(D)", new ImageIcon(getClass().getResource("edit-delete-6.png"))); deleteMenuItem.setMnemonic('D'); popupMenu.add(deleteMenuItem);/*from ww w.j av a2s . c o m*/ deleteMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteRecord(); } }); popupMenu.addSeparator(); JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png"))); editMenuItem.setMnemonic('E'); popupMenu.add(editMenuItem); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow())); showUpdateRecordDialog(record); } }); // ??popup menu table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (disable) return; JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(e.getPoint()); if (SwingUtilities.isRightMouseButton(e)) { if (row >= 0 && col >= 0) { table.setRowSelectionInterval(row, row); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } else if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 2) { if (row >= 0 && col >= 0) { // Record record = model.getRecord(table.convertRowIndexToModel(row)); // showUpdateRecordDialog(record); } } } } }); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table.getActionMap().put("Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { if (disable) return; //do something on JTable enter pressed int row = table.getSelectedRow(); if (row >= 0) { Record record = model.getRecord(table.convertRowIndexToModel(row)); showUpdateRecordDialog(record); } } }); }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.GUIComponents.XYSequencing.java
private void setControlDefaults() { pmdp_ = new PlateMapDrawPanel(this); sap_ = SeqAcqProps.getInstance();/* w w w . j a v a 2s . c om*/ plateMapBasePanel.setLayout(new BorderLayout()); plateMapBasePanel.add(pmdp_, BorderLayout.CENTER); tableModel_ = new FOVTableModel(pp_); searchFOVtableModel_ = new FOVTableModel(pp_); //Not sure if this is the best way, but try it for now. tableModel_.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { } }); fovTable_ = new JTable(); fovTable_.setModel(tableModel_); fovTable_.setSurrendersFocusOnKeystroke(true); fovTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); JScrollPane scroller = new javax.swing.JScrollPane(fovTable_); fovTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(190, 130)); fovTablePanel.setLayout(new BorderLayout()); fovTablePanel.add(scroller, BorderLayout.CENTER); final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete FOV"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fovTable_.getSelectedRow(); tableModel_.removeRow(r); } }); JMenuItem addItem = new JMenuItem("Add FOV"); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fovTable_.getSelectedRow(); tableModel_.insertRow(r, new FOV("A1", pp_, 6000)); } }); JMenuItem goToFOVItem = new JMenuItem("Go to FOV"); goToFOVItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fovTable_.getSelectedRow(); // FOV fov = tableModel_.getData().get(r); xyzmi_.gotoFOV(tableModel_.getData().get(r)); if (!zAsOffset_) { double zval = tableModel_.getData().get(r).getZ(); xyzmi_.moveZAbsolute(zval); } else { // obviously, this isn't quite right - we want to get // the offset of the CURRENT FOV (perhaps from parent in // later implementations?) and subtract from that of the // NEWLY SELECTED FOV. // TODO: fix for proper zAsOffset behaviour. // Wait for move completion while (xyzmi_.isStageBusy()) { System.out.println("Stage moving..."); } ; if (parent_.checkifAFenabled()) { // If we have gone to the FOV, and have AF, do AF xyzmi_.customAutofocus(parent_.getAFOffset()); } else { // If we don't have AF, go to the 'good offset position' xyzmi_.moveZAbsolute(parent_.getFixedAFDefault()); } //Now do the relative shift xyzmi_.moveZRelative(tableModel_.getData().get(r).getZ()); System.out.println("Z value" + tableModel_.getData().get(r).getZ()); } } }); popupMenu.add(addItem); popupMenu.add(deleteItem); popupMenu.add(goToFOVItem); fovTable_.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { // System.out.println("pressed"); } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable) e.getSource(); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); if (!source.isRowSelected(row)) { source.changeSelection(row, column, false, false); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); // fovTable_.setDefaultRenderer(FOV.class, new TableRenderer()); setupInsertComboBox(); }
From source file:cfa.vo.sed.science.stacker.SedStackerFrame.java
private void sedsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sedsTableMousePressed if (evt.isPopupTrigger()) { JTable source = (JTable) evt.getSource(); int row = source.rowAtPoint(evt.getPoint()); int column = source.columnAtPoint(evt.getPoint()); if (!source.isRowSelected(row)) source.changeSelection(row, column, false, false); sedsTable.changeSelection(row, column, false, false); jPopupMenu2.show(evt.getComponent(), evt.getX(), evt.getY()); }//from ww w.ja va 2 s . c o m }
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 ww w . j av a 2s. 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.peterbochs.PeterBochsDebugger.java
public void instructionTableMouseClicked(MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) { JTable jTable = (JTable) evt.getSource(); if (jTable == instructionTable) { Global.clickedWhichInstructionPanel = 0; } else {/*from w w w. j av a2s. c om*/ Global.clickedWhichInstructionPanel = 1; } // select Point p = evt.getPoint(); int rowNumber = jTable.rowAtPoint(p); int columnNumber = jTable.columnAtPoint(p); ListSelectionModel model = jTable.getSelectionModel(); model.setSelectionInterval(rowNumber, rowNumber); jTable.getColumnModel().getSelectionModel().setSelectionInterval(columnNumber, columnNumber); // end select getJInstructionPanelPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY()); } }