public ClassSelector(Comparator<ClassEntry> comparator) { m_comparator = comparator; // configure the tree control setRootVisible(false); setShowsRootHandles(false); setModel(null); // hook events addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { if (m_listener != null && event.getClickCount() == 2) { // get the selected node TreePath path = getSelectionPath(); if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { ClassSelectorClassNode node = (ClassSelectorClassNode)path.getLastPathComponent(); m_listener.onSelectClass(node.getClassEntry()); } } } }); // init defaults m_listener = null; }
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { boolean ascending = false; public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //System.out.println("Sorting ..."); //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; //boolean ascending = (shiftPressed == 0); if (column == sortBy) ascending = !ascending; else ascending = true; sorter.sortByColumn(column, ascending); tableView.getTableHeader().updateUI(); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
public WhatIfPlot(double[] xAxis) { super(); this.xAxis = xAxis; // Adds popup menu this.addMouseListener(new MouseAdapter() { /** * Invoked when the mouse has been clicked on a component. */ @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(WhatIfPlot.this, e.getX(), e.getY()); } } }); }
public void addChoice(final String key, String displayText) { final JRadioButton rb = new JRadioButton(displayText); if( doubleClickToSelect ) { rb.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if( e.getClickCount() >= 2 ) { addClicked(key); } } }); } choices.addButton(rb, key); // Add after the instructions label and any existing choices add(rb, choices.size()); }
private Box.Filler simpleFiller() { Box.Filler filler = new Box.Filler( new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767)); filler.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent me) { setGlassPane(docker); SwingUtilities.invokeLater(() -> { getGlassPane().setVisible(true); }); } }); return filler; }
public JCheckBoxList() { setCellRenderer(new CellRenderer()); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); if (index != -1) { JCheckBox checkbox = getModel().getElementAt(index); if (e.getPoint().x < checkbox.getHorizontalTextPosition()) { checkbox.setSelected(!checkbox.isSelected()); } repaint(); } } }); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
private static void showModalDialog(Frame targetFrame) { Dialog dialog = new Dialog(targetFrame, true); dialog.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { passed = true; dialog.dispose(); } }); dialog.setSize(400, 300); dialog.setTitle("Modal Dialog!"); clickOnModalDialog(dialog); dialog.setVisible(true); }
/** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 800, 450); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); final JButton btnNewButton = new JButton("\u62CD\u7167"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { flag = 1;// ��̬��������Ϊ1���Ӷ����°�ťʱ��ֹͣ����ͷ�ĵ��� } }); btnNewButton.setBounds(33, 13, 113, 27); frame.getContentPane().add(btnNewButton); label = new JLabel(""); label.setBounds(0, 0, 800, 450); frame.getContentPane().add(label); }
/** * Creates the process list * * @return JComponent */ private JComponent buildList() { list = new JList<>(); list.setCellRenderer(new CellRenderer(list.getCellRenderer())); list.setTransferHandler(new ProcessTransferHandler()); list.setDragEnabled(true); list.setDropMode(DropMode.ON_OR_INSERT); list.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getClickCount() % 2 == 0) { ProcessInformationPane.showDialog(list.getSelectedValue()); } } }); return ScrollFactory.pane(list).create(); }
/** * GlassPane constructor comment. * * @param Container a */ protected BusyGlassPane(Component activeComponent, boolean stopClosing) { this.stopClosing = stopClosing; // add adapters that do nothing for keyboard and mouse actions addMouseListener(new MouseAdapter() { // We don't care about any events }); addKeyListener(new KeyAdapter() { // We don't care about any events }); setActiveComponent(activeComponent); }
public static void initTestWindow() { mainFrame = new Frame(); mainFrame.setTitle("TestWindow"); mainFrame.setBounds(700, 10, 300, 300); mainFrame.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int ex = e.getModifiersEx(); if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) { AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set."); } else { AltGraphModifierTest.pass(); } } }); mainFrame.setVisible(true); }
/** * Constructor */ public HyperlinkLabel() { super(); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent evt) { if (_url != null) { Util.browse(_url, getText()); } } }); setForeground(Color.BLUE); }
private MouseListener createMouseListener() { return new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { JComponent comp = (JComponent)event.getSource(); Item item = null; if (comp instanceof JList) { JList list = (JList)comp; Point p = event.getPoint(); int index = list.locationToIndex(p); if (index >= 0 && !list.getCellBounds(index, index).contains(p)) { index = -1; } if (index >= 0) { item = (Item)list.getModel().getElementAt(index); } } Action[] actions = null == item ? category.getActions() : item.getActions(); JPopupMenu popup = Utilities.actionsToPopup( actions, getComponent() ); Utils.addCustomizationMenuItems( popup, getPalettePanel().getController(), getPalettePanel().getSettings() ); popup.show(comp, event.getX(), event.getY()); } } }; }
public MyTableHeader( TableColumnModel model ) { super( model ); addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if( e.getClickCount() != 1 ) return; int column = columnAtPoint( e.getPoint() ); if( column > 0 && getModel() instanceof TaskListModel ) { ((TaskListModel)getModel()).toggleSort( column ); repaint(); } } }); this.setReorderingAllowed( false ); }
public static void addListeners() { // 暂时停止使用,仅留作demo,日后需要时再使用 MainWindow.mainWindow.getTabbedPane().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); int index = MainWindow.mainWindow.getTabbedPane().getSelectedIndex(); switch (index) { case 6: break; default: break; } } }); }
public ExpandablePanel(JLabel l, JPanel p, final Icon ei, final Icon ci) { this.panel = p; this.label = l; this.ci = ci; this.ei = ei; this.label.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if(panel.isVisible()) { colapse(); } else { expand(); } } }); }
/** * Adds handling of edit and stop-edit events after all other handlers have been installed. */ protected void installDoubleClickHandler() { graphControl.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (isEnabled()) { if (!e.isConsumed() && isEditEvent(e)) { Object cell = getCellAt(e.getX(), e.getY(), false); if (cell != null && getGraph().isCellEditable(cell)) { startEditingAtCell(cell, e); } } else { // Other languages use focus traversal here, in Java // we explicitely stop editing after a click elsewhere stopEditing(!invokesStopCellEditing); } } } }); }
/** Post-processes an already constructed toolbar. */ private void processToolBar(JToolBar toolBar) { for (int i = 0; i < toolBar.getComponentCount(); i++) { Component element = toolBar.getComponent(i); if (element instanceof JButton) { JButton button = (JButton) element; Action action = button.getAction(); if (action != null) { getJGraph().addAccelerator(action); } } } // ensure the JGraph gets focus as soon as the graph panel // is clicked anywhere // for reasons not clear to me, mouse listeners do not work on // the level of the JGraphPanel toolBar.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { getJGraph().requestFocus(); } }); }
private void enableDeletes() { //deleteOneClass.setEnabled(classes>1); //todo zanzottera inserito controllo inizialmente non si possono cancellare le 2 classi deleteOneClass.setEnabled(classes > MINCLASSES); /*It seems the only way to implement row deletion...*/ this.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (classes > MINCLASSES && (columnAtPoint(e.getPoint()) == getColumnCount() - 1) && getRowCount() > 1) { setRowSelectionInterval(rowAtPoint(e.getPoint()), rowAtPoint(e.getPoint())); deleteSelectedClasses(); } } }); getColumnModel().getColumn(getColumnCount() - 1).setMinWidth(20); getColumnModel().getColumn(getColumnCount() - 1).setMaxWidth(20); }
/** * */ private void buildTree() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("user"); tree = new JTree(root); tree.putClientProperty("JTree.lineStyle", "Angled"); tree.setCellRenderer(new NavigationTreeCellRenderer()); tree.setShowsRootHandles(true); DefaultTreeSelectionModel model = new DefaultTreeSelectionModel(); model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); graphsCategory = new DefaultMutableTreeNode("graphs"); mouseAdapter = new MouseAdapter() { public void mouseClicked(MouseEvent e) { itemSelected(e); } }; tree.addMouseListener(mouseAdapter); root.add(graphsCategory); loadGraphs(); }
/** * Creates a title bar with the given text and ability to close the parent jframe * @param titleText the text to display as the title, can be HTML formatted * @param parent the jframe to close when the X is clicked */ public UITitleBar(String titleText, JFrame parent) { setBackground(Color.decode("#7289DA")); setLayout(new BorderLayout()); JLabel title = new JLabel(titleText); title.setFont(TransparentDiscord.boldFont.deriveFont(Font.PLAIN, 16)); title.setBorder(new EmptyBorder(20,20,20,20)); add(title, BorderLayout.WEST); JLabel closeButton = new JLabel("X"); closeButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { parent.setVisible(false); } }); closeButton.setBorder(new EmptyBorder(20,20,20,20)); closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); add(closeButton, BorderLayout.EAST); }
/** * Constructs a list item around a text channel * @param channel */ public UIChannelListItem(TextChannel channel) { this(channel.getId()); displayName = new JLabel(channel.getName()); displayName.setFont(TransparentDiscord.defaultFont.deriveFont(Font.PLAIN, 16)); displayName.setBorder(new EmptyBorder(10,10,10,10)); add(displayName, BorderLayout.CENTER); //When clicked, open the chat addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { TransparentDiscord.openChat(channel); } }); }
public void selectMenuItem() { final LoggingRecorder lr = new LoggingRecorder(); final List<JMenuItem> items = new ArrayList<JMenuItem>(); siw(new Runnable() { @Override public void run() { JMenu AMenu = (JMenu) menus.get(0); AMenu.doClick(); items.addAll(getMenuComponents(AMenu)); } }); items.get(1).addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { RMenuItem rMenuItem = new RMenuItem(items.get(1), null, null, lr); rMenuItem.mouseButton1Pressed(e); } }); IDevice d = Device.getDevice(); d.click(items.get(1), Buttons.LEFT, 1, 5, 5); Call call = lr.getCall(); AssertJUnit.assertEquals("select_menu", call.getFunction()); AssertJUnit.assertEquals("A Menu>>Both text and icon", call.getState()); }
public void close () { final long endTime = System.currentTimeMillis(); new Thread(new Runnable() { public void run () { if (endTime - startTime < minMillis) { addMouseListener(new MouseAdapter() { public void mousePressed (MouseEvent evt) { dispose(); } }); try { Thread.sleep(minMillis - (endTime - startTime)); } catch (InterruptedException ignored) { } } EventQueue.invokeLater(new Runnable() { public void run () { dispose(); } }); } }, "Splash").start(); }
public void setPopMenu(JPopupMenu _menu) { menu = _menu; if (menu != null) { addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { setSelectionRow(getClosestRowForLocation(e.getX(), e.getY())); if (getSelectionCount() > 0 && isRootNotSelected()) { menu.show(CustomTree.this, e.getX(), e.getY()); } } else if (e.getClickCount() == 2) { try { if (action != null) action.call(); } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } } } }); } }
public UserTableHeaderCellRenderer(JTable table) { this.tableModel = (UserTableModel) table.getModel(); this.tableHeader = table.getTableHeader(); selectBox = new JCheckBox(tableModel.getColumnName(0)); selectBox.setSelected(false); tableHeader.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 0) { int selectColumn = tableHeader.columnAtPoint(e.getPoint()); if (selectColumn == 0) { boolean value = !selectBox.isSelected(); selectBox.setSelected(value); tableModel.selectAll(value); tableHeader.repaint(); } } } }); }
/** * Initialises all listening activity on the display, and * calls {@link #activateListening()}. */ @Override protected void installListeners() { getSimulatorModel().addListener(this, Change.GRAMMAR, Change.toChange(getResourceKind())); // adds a mouse listener that offers a popup menu with a detach action getTabPane().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { int index = getTabPane().indexAtLocation(e.getX(), e.getY()); if (index >= 0) { ResourceTab tab = (ResourceTab) getTabPane().getComponentAt(index); if (tab != getMainTab()) { createDetachMenu(tab).show(ResourceDisplay.this, e.getX(), e.getY()); } } } } }); activateListening(); }
public JButton changePlayerGenderRight(){ JButton changePlayerGender = new JButton( readXML.readXML(1,"currency",2)); changePlayerGender.setForeground(setColor.getColor(setColor.button,1)); changePlayerGender.setBackground(null); changePlayerGender.setBorder(null); changePlayerGender.setFont(setFont.getFont(setFont.buttonFontI)); changePlayerGender.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { int genderId = Integer.parseInt(cacheHandle.readCache(cacheHandle.player,"gender")); switch (genderId){ case 0: genderId ++; cacheHandle.setCache(cacheHandle.player,"gender",Integer.toString(genderId)); loadPanel.loadPanel(loadPanel.creatorPlayerPanelId); break; case 1: break; } } }); return changePlayerGender; }
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { boolean ascending = false; public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //Util.debug("Sorting ..."); //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; //boolean ascending = (shiftPressed == 0); if (column == sortBy) ascending = !ascending; else ascending = true; sorter.sortByColumn(column, ascending); tableView.getTableHeader().updateUI(); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
public CheckRenderer(final JList<Object> list) { this.list = list; list.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int index = list.locationToIndex(e.getPoint()); Point p2 = list.indexToLocation(index); Rectangle r = new Rectangle(p2.x, p2.y, getPreferredSize().height, getPreferredSize().height); if (r.contains(e.getPoint())) { CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index); node.setSelected(!node.isSelected()); list.repaint(); e.consume(); } } }); this.setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height - 5)); startBackground = this.getBackground(); }
/** * Constructor from owner, GraphicsConfiguration and content. */ public Splash(Window owner, GraphicsConfiguration gc, final JComponent content) { super(owner, gc); getContentPane().setLayout(new BorderLayout()); content.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); getContentPane().add(content, BorderLayout.CENTER); content.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { // when the content pane is clicked, hide it setVisible(false); } }); validate(); pack(); }
public WindowNotification() { m_window = new JWindow(); m_window.setAlwaysOnTop(true); m_listener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { fireListeners(CLICKED); if (m_closeOnClick) removeFromManager(); } }; setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); setPanel(new JPanel()); }
private void addTextArea(int x, int y) { int left = getCanvas().getBounds().x + x; int top = getCanvas().getBounds().y + y; textArea.setVisible(true); textArea.setBorder(new EmptyBorder(0, 0, 0, 0)); textArea.setText(""); textArea.setBounds(left, top, (int)(getCanvas().getBounds().getWidth() * getCanvas().getScale()) - left, (int)(getCanvas().getBounds().getHeight() * getCanvas().getScale()) - top); textArea.setFont(getScaledFont()); textArea.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { TextTool.this.mousePressed(e, new Point(0, 0)); } }); getCanvas().addComponent(textArea); textArea.requestFocus(); }
private MouseAdapter onAddNewTDTab() { return new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { JTabbedPane tabbedPane = (JTabbedPane) me.getSource(); if (tabbedPane.getSelectedIndex() != -1 && getSelectedData() == null) { Rectangle rect = tabbedPane.getUI(). getTabBounds(tabbedPane, tabbedPane.getSelectedIndex()); if (rect.contains(me.getPoint())) { tabbedPane.setSelectedIndex(tabbedPane.getSelectedIndex() - 1); addNewTestData(tabbedPane); } } } }; }
public AboutDialog(Window owner, String version) { super(owner); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { AboutDialog.this.dispose(); } }); addKeyListener(this); setTitle("Open Data Migrator for Hitachi Content Platform"); ClassLoader cl = this.getClass().getClassLoader(); SplashPanel panel = new SplashPanel( new ImageIcon(cl.getResource("images/HCPDataMigratorSplashBackground.png")) .getImage()); getContentPane().add(panel); setModal(true); pack(); setLocationRelativeTo(owner); setResizable(false); setVisible(true); }
@Override protected void prepareControls() { JDesktopPane desktopPane = new JDesktopPane(); JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false); bottomFrame.setSize(220, 220); super.propagateAWTControls(bottomFrame); desktopPane.add(bottomFrame); bottomFrame.setVisible(true); JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false); topFrame.setSize(200, 200); topFrame.add(new JButton("LW Button") { { addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { lwClicked = true; } }); } }); desktopPane.add(topFrame); topFrame.setVisible(true); JFrame frame = new JFrame("Test Window"); frame.setSize(300, 300); frame.setContentPane(desktopPane); frame.setVisible(true); locTopFrame = topFrame.getLocationOnScreen(); locTarget = new Point(locTopFrame.x + bottomFrame.getWidth() / 2, locTopFrame.y + bottomFrame.getHeight()/2); }