List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:Main.java
public void mouseMoved(MouseEvent evt) { JTableHeader header = (JTableHeader) evt.getSource(); JTable table = header.getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); TableColumn col = null;//from w w w . ja v a2 s.c o m if (vColIndex >= 0) { col = colModel.getColumn(vColIndex); } if (col != curCol) { header.setToolTipText((String) tips.get(col)); curCol = col; } }
From source file:Main.java
@Override public void mousePressed(MouseEvent e) { JLabel label = (JLabel) e.getSource(); initLabelLocation = label.getLocation(); initMouseLocationOnScreen = e.getLocationOnScreen(); }
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 . jav a 2 s . 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:Main.java
private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(x, y); if (path == null) return;// w w w. j a v a 2 s.c o m DefaultMutableTreeNode rightClickedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] selectionPaths = tree.getSelectionPaths(); boolean isSelected = false; if (selectionPaths != null) { for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (rightClickedNode.isLeaf()) { JPopupMenu popup = new JPopupMenu(); final JMenuItem refreshMenuItem = new JMenuItem("refresh"); refreshMenuItem.addActionListener(ev -> System.out.println("refresh!")); popup.add(refreshMenuItem); popup.show(tree, x, y); } }
From source file:Main.java
MyJTree(DefaultMutableTreeNode dmtn) { super(dmtn);/*from www . j a va2 s .c o m*/ mi.addActionListener(this); mi.setActionCommand("insert"); popup.add(mi); mi = new JMenuItem("Remove this node"); mi.addActionListener(this); mi.setActionCommand("remove"); popup.add(mi); addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { popup.show((JComponent) e.getSource(), e.getX(), e.getY()); } } }); }
From source file:com.github.fritaly.dualcommander.event.ColumnEventHelper.java
@Override public void mouseReleased(MouseEvent e) { if (resizing) { if (e.getSource() instanceof JTableHeader) { final TableColumn column = ((JTableHeader) e.getSource()).getColumnModel() .getColumn(resizingColumn); if (column != null) { int newWidth = column.getPreferredWidth(); if (newWidth != oldWidth) { listener.columnResized(new ColumnEvent(column)); }/*from w w w. j av a2 s.c o m*/ } } } resizing = false; resizingColumn = -1; oldWidth = -1; }
From source file:com.github.fritaly.dualcommander.event.ColumnEventHelper.java
@Override public void mousePressed(MouseEvent e) { // capture start of resize if (e.getSource() instanceof JTableHeader) { final TableColumn column = ((JTableHeader) e.getSource()).getResizingColumn(); if (column != null) { resizing = true;//from www . ja va 2 s .c om resizingColumn = column.getModelIndex(); oldWidth = column.getPreferredWidth(); } else { resizingColumn = -1; oldWidth = -1; } } }
From source file:Main.java
@Override public void mouseDragged(MouseEvent e) { if (initLabelLocation == null || initMouseLocationOnScreen == null) { return;//w w w . j a v a 2 s . c o m } JLabel label = (JLabel) e.getSource(); Point mouseLocation = e.getLocationOnScreen(); int deltaX = mouseLocation.x - initMouseLocationOnScreen.x; int deltaY = mouseLocation.y - initMouseLocationOnScreen.y; int labelX = initLabelLocation.x + deltaX; int labelY = initLabelLocation.y + deltaY; label.setLocation(labelX, labelY); }
From source file:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/* www .ja v a 2 s. c o m*/ JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:Demo.HistGraph.java
@Override public void mouseReleased(MouseEvent e) { if (e.getSource() == paraSelector) { int selected = paraSelector.getSelectedIndex(); if (charts[selected] == null) { charts[selected] = CreateChart(paraType_list.get(selected)); }//from w ww. ja va 2 s . c o m chartPane.setChart(charts[selected]); } }