List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:components.SimpleTableDemo.java
public SimpleTableDemo() { super(new GridLayout(1, 0)); String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) }, { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) }, { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) }, { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) }, { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/* ww w . j a va 2 s . co m*/ if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.ActionList.java
private void setupList() { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override//from w w w .j av a 2 s. c o m public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fireAction(); } } }); list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { fireAction(); } }); list.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getExtendedKeyCode() == KeyEvent.VK_SPACE) { fireAction(); } if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) { fireAction(); } } }); }
From source file:be.tutul.naheulcraft.launcher.auth.LogInForm.java
private void createInterface() { setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = 2;/*from w ww . ja va 2 s .c om*/ constraints.gridx = 0; constraints.gridy = -1; constraints.weightx = 1.0D; add(Box.createGlue()); JLabel usernameLabel = new JLabel("Pseudo : "); Font labelFont = usernameLabel.getFont().deriveFont(1); Font smalltextFont = usernameLabel.getFont().deriveFont(labelFont.getSize() - 2.0F); usernameLabel.setFont(labelFont); add(usernameLabel, constraints); add(this.usernameField, constraints); add(Box.createVerticalStrut(10), constraints); JLabel passwordLabel = new JLabel("Mot de passe :"); passwordLabel.setFont(labelFont); add(passwordLabel, constraints); add(this.passwordField, constraints); JLabel forgotPasswordLabel = new JLabel("(oubli ?)"); forgotPasswordLabel.setCursor(new Cursor(12)); forgotPasswordLabel.setFont(smalltextFont); forgotPasswordLabel.setHorizontalAlignment(4); forgotPasswordLabel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { Util.openLink(Variables.lost); } catch (Exception e1) { LogInForm.this.login.getLauncher().getLogger() .error("Impossible d'ouvrir le lien pour les logins oublis"); JOptionPane.showMessageDialog(LogInForm.this.login.getLauncher().getPanel(), "Impossible d'ouvrir la page\nRendez-vous sur le site de NaheulCraft pour rcuprer vos identifiants", "Impossible d'ouvrir l'URL", 0); } } }); add(forgotPasswordLabel, constraints); createUserDropdownPanel(labelFont); add(this.userDropdownPanel, constraints); add(Box.createVerticalStrut(10), constraints); }
From source file:com.intuit.tank.tools.debugger.SelectDialog.java
/** * @param arg0/*from w w w. j a v a2s . c o m*/ */ public SelectDialog(Frame f, List<SELECTION_TYPE> items, String itemType, boolean singleSelection) { super(f, true); setLayout(new BorderLayout()); this.items = items; filterField = new JTextField(); filterField.addKeyListener(new KeyHandler()); list = new JList(items.toArray()); list.setSelectionMode(singleSelection ? ListSelectionModel.SINGLE_SELECTION : ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { okBT.setEnabled(list.getSelectedIndex() != -1); } }); list.addMouseListener(new MouseAdapter() { /** * @{inheritDoc */ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { select(); } } }); JPanel labelPanel = new JPanel(new GridLayout(singleSelection ? 1 : 2, 1, 0, 5)); labelPanel.add(new JLabel("Select a " + itemType + ".")); if (!singleSelection) { String key = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 ? "" : "control"; System.out.println(key); labelPanel.add(new JLabel("Hold down the " + key + " key to select multiple " + itemType + ".")); } add(labelPanel, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(list); JPanel centerPanel = new JPanel(new BorderLayout()); centerPanel.add(filterField, BorderLayout.NORTH); centerPanel.add(sp, BorderLayout.CENTER); add(centerPanel, BorderLayout.CENTER); add(createButtonPanel(), BorderLayout.SOUTH); setSize(new Dimension(400, 500)); setBounds(new Rectangle(getSize())); setPreferredSize(getSize()); WindowUtil.centerOnParent(this); }
From source file:fi.marketing.list.ui.DashboardUI.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.//from w w w. j av a 2s . co m */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { db = new javax.swing.JFileChooser(); contactListName = new javax.swing.JTextField(); nameNewMarketingList = new javax.swing.JTextField(); addContactListButton = new javax.swing.JButton(); createMarketingListButton = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); infoArea1 = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); infoArea2 = new javax.swing.JTextArea(); jScrollPane3 = new javax.swing.JScrollPane(); resultArea = new javax.swing.JTextArea(); selectType = new javax.swing.JComboBox<>(); jScrollPane4 = new javax.swing.JScrollPane(); infoAreaStatistics = new javax.swing.JTextArea(); jTextField1 = new javax.swing.JTextField(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); db.setControlButtonsAreShown(false); String directory = getClass().getProtectionDomain().getCodeSource().getLocation().toString(); db.setCurrentDirectory(new java.io.File(directory)); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Dashboard"); contactListName.setText("Give a Name to new Contact List"); contactListName.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { contactListName.setText(""); } }); nameNewMarketingList.setText("Give a Name to new Marketing List"); nameNewMarketingList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { nameNewMarketingList.setText(""); } }); addContactListButton.setText("Add"); addContactListButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addContactListButtonActionPerformed(evt); } }); createMarketingListButton.setText("Create"); createMarketingListButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { createMarketingListButtonActionPerformed(evt); } }); infoArea1.setColumns(20); infoArea1.setRows(5); infoArea1.setText( "There are in the resources directory \n contact files koe1.txt, test1.txt and test2.txt to choose from. \n You can try to upload the same file twice \n and see that duplicates are not produced."); infoArea1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { infoArea1.setText(""); } }); jScrollPane1.setViewportView(infoArea1); infoArea2.setColumns(20); infoArea2.setRows(5); jScrollPane2.setViewportView(infoArea2); resultArea.setColumns(20); resultArea.setRows(5); jScrollPane3.setViewportView(resultArea); selectType.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Collect Phone Numbers", "Collect Email Addresses" })); infoAreaStatistics.setColumns(20); infoAreaStatistics.setRows(5); jScrollPane4.setViewportView(infoAreaStatistics); jTextField1.setText("Upload more Contacts from a File"); jTextField1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { jTextField1.setText(""); openAFileChooser(); } }); jMenu1.setText("File"); jMenuItem1.setText("Open a file"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuBar1.add(jMenu1); jMenu2.setText("Help"); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(30, 30, 30).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 393, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(selectType, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(createMarketingListButton)) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING)) .addComponent(nameNewMarketingList, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 473, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(contactListName, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(addContactListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(14, 14, 14) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addContactListButton).addComponent(contactListName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(12, 12, 12) .addComponent(nameNewMarketingList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(selectType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(createMarketingListButton)) .addGap(18, 18, 18) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(63, 63, 63)) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))); pack(); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java
private void init() { this.srcPoint = new Point(); this.selectionColor = createSelectionColor(); this.rubberBandMouseListener = new MouseAdapter() { @Override//from ww w . j a v a 2s . c o m public void mousePressed(MouseEvent e) { int index = locationToIndex(e.getPoint()); Rectangle rect = getCellBounds(index, index); if (!rect.contains(e.getPoint())) { clearSelection(); getSelectionModel().setAnchorSelectionIndex(-1); getSelectionModel().setLeadSelectionIndex(-1); setFocusable(false); } else { setFocusable(true); } } @Override public void mouseReleased(MouseEvent e) { setFocusable(true); rubberBand = null; repaint(); } }; this.rubberBandMouseMotionListener = new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { setFocusable(true); if (rubberBand == null) { srcPoint.setLocation(e.getPoint()); } Point destPoint = e.getPoint(); rubberBand = new Path2D.Double(); rubberBand.moveTo(srcPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, srcPoint.y); rubberBand.lineTo(destPoint.x, destPoint.y); rubberBand.lineTo(srcPoint.x, destPoint.y); rubberBand.closePath(); setSelectedIndices(getIntersectsIdices(rubberBand)); repaint(); } }; addMouseListener(rubberBandMouseListener); addMouseMotionListener(rubberBandMouseMotionListener); }
From source file:ru.codemine.pos.ui.windows.users.UsersListWindow.java
@Override public void setupActionListeners() { setNewActionListener(newUser);// www . j a v a 2 s . c om setEditActionListener(editUser); setDeleteActionListener(deleteUser); setRefreshActionListener(refreshUsersList); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); int row = table.rowAtPoint(p); if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { menuItemEdit.doClick(); } } }); actionListenersInit = true; }
From source file:Splash.java
public Splash(JFrame f, String progName, String fileName) { super();/*from ww w . j ava2s. c om*/ // Can't use Swing border on JWindow: not a JComponent. // setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); im = new ImageIcon(fileName); if (im.getImageLoadStatus() != MediaTracker.COMPLETE) JOptionPane.showMessageDialog(f, "Warning: can't load image " + fileName + "\n" + "Please be sure you have installed " + progName + " correctly", "Warning", JOptionPane.WARNING_MESSAGE); int w = im.getIconWidth(), h = im.getIconHeight(); setSize(w, h); UtilGUI.center(this); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { dispose(); } }); addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { dispose(); } }); }
From source file:ru.codemine.pos.ui.windows.stores.StoresListWindow.java
@Override public void setupActionListeners() { setNewActionListener(newStore);/* www . j a va 2 s . com*/ setEditActionListener(editStore); setDeleteActionListener(deleteStore); setRefreshActionListener(refreshStoreList); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); int row = table.rowAtPoint(p); if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { menuItemEdit.doClick(); } } }); actionListenersInit = true; }
From source file:de.tbuchloh.kiskis.gui.widgets.BasicTextField.java
private void init() { _copyAction = M.createAction(this, "onCopyToClipboard"); _specialActionsMenu = new JPopupMenu(); for (final Object element : getContextMenuActions()) { final Action act = (Action) element; _specialActionsMenu.add(act);/*w w w. j a va 2 s. c o m*/ } addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { return; } final int x = 0; // _pwdField.getWidth() // - _specialActionsMenu.getWidth(); final int y = getHeight(); LOG.debug("Show context menu x=" + x + ", y=" + y); _specialActionsMenu.show(BasicTextField.this, x, y); } }); }