List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("JToolTip Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton b1 = new JButton("Button 1") { public JToolTip createToolTip() { JToolTip tip = super.createToolTip(); tip.setForeground(Color.YELLOW); return tip; }/*from ww w .j a va 2s.c om*/ public Point getToolTipLocation(MouseEvent event) { return new Point((event.getX() + 100), (event.getY() + 100)); } }; b1.setToolTipText("HELLO"); frame.add(b1, BorderLayout.NORTH); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextPane tp = new JTextPane(); JButton withFocus = new JButton("Select with focus"); tp.addMouseListener(new MouseAdapter() { @Override//from w w w.java2s . com public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) { tp.selectAll(); } } }); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(tp)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { final JPopupMenu menu = new JPopupMenu(); JMenuItem item = new JMenuItem("Item Label"); menu.add(item);/*w w w . j a v a2 s.co m*/ JButton component = new JButton("button"); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Compound Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton bevelLineButton = new JButton("Bevel Line"); Border redBorder = BorderFactory.createLineBorder(Color.MAGENTA, 2, true); bevelLineButton.setBorder(redBorder); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(1, 2)); contentPane.add(bevelLineButton);// ww w . j a v a2 s .co m frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JTable table = new JTable(22, 5); table.setPreferredScrollableViewportSize(new Dimension(400, 300)); final JScrollPane scrollPane = new JScrollPane(table); JButton cornerButton = new JButton("#"); scrollPane.setCorner(JScrollPane.UPPER_TRAILING_CORNER, cornerButton); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JFrame frame = new JFrame(); frame.add(scrollPane);/* w w w .j a v a 2 s . c o m*/ frame.pack(); frame.setVisible(true); }
From source file:ABevelBorderLoweredBevelBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Bevel Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border loweredBorder = BorderFactory.createLoweredBevelBorder(); JButton button = new JButton("Raised"); button.setBorder(loweredBorder);//from w w w. j a va 2 s . c o m frame.add(button); frame.setSize(300, 100); frame.setVisible(true); }
From source file:DualModal.java
public static void main(String args[]) { final JFrame frame1 = new JFrame("Left"); final JFrame frame2 = new JFrame("Right"); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Left"); JButton button2 = new JButton("Right"); frame1.add(button1);// w w w.j av a 2 s. c om frame2.add(button2); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { JButton source = (JButton) e.getSource(); JOptionPane pane = new JOptionPane("New label", JOptionPane.QUESTION_MESSAGE); pane.setWantsInput(true); JDialog dialog = pane.createDialog(frame2, "Enter Text"); // dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL); dialog.setVisible(true); String text = (String) pane.getInputValue(); if (!JOptionPane.UNINITIALIZED_VALUE.equals(text) && text.trim().length() > 0) { source.setText(text); } } }; button1.addActionListener(listener); button2.addActionListener(listener); frame1.setBounds(100, 100, 200, 200); frame1.setVisible(true); frame2.setBounds(400, 100, 200, 200); frame2.setVisible(true); }
From source file:FlowLayoutExample.java
public static void main(String[] args) { JPanel panel = new JPanel(); JTextArea area = new JTextArea("text area"); area.setPreferredSize(new Dimension(100, 100)); JButton button = new JButton("button"); panel.add(button);//w w w . j ava 2s. co m panel.add(new JScrollPane(area)); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:ActionListenerTest2.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select File"); button.addActionListener(new MyActionListener()); frame.add(button);/*from w w w . j a v a 2s . co m*/ frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton closeButton = new JButton("Close"); contentPane.add(closeButton);/*from w w w.ja v a 2s . c o m*/ closeButton.addActionListener(e -> System.exit(0)); // Add a MouseListener to the JButton closeButton.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { closeButton.setText("Mouse has entered!"); } @Override public void mouseExited(MouseEvent e) { closeButton.setText("Mouse has exited!"); } }); frame.pack(); frame.setVisible(true); }