List of usage examples for javax.swing JButton setText
@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.") public void setText(String text)
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton button = new JButton(); button.setText("<html>" + "This is a" + "<br><i>" + "swing button" + "</i></html>"); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton button = new JButton(); button.setText("<html><center>" + "This is a" + "<br>" + "swing button" + "</center></html>"); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(800, 600);//from w ww .j av a 2 s.c om frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); device.setFullScreenWindow(frame); device.setDisplayMode(new DisplayMode(800, 600, 32, 60)); frame.setVisible(true); JButton btn = new JButton(); btn.setText("Button"); JPanel panel = new JPanel(); panel.add(btn); frame.add(panel); btn.addActionListener(e -> { JOptionPane.showMessageDialog(frame.getContentPane(), "JOptionPane"); }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("icon.gif"); Action action = new AbstractAction("Button Label", icon) { public void actionPerformed(ActionEvent evt) { }//from w w w. ja va 2s . co m }; JButton c1 = new JButton(action); c1.setText(null); c1.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c1); JToggleButton c2 = new JToggleButton(action); c2.setText(null); c2.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c2); JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" }); c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width c3.setMaximumSize(c3.getMinimumSize()); toolbar.add(c3); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); device.setFullScreenWindow(frame);/* w w w.ja va 2 s . c om*/ device.setDisplayMode(new DisplayMode(800, 600, 32, 60)); frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent we) { if (programmatic) { programmatic = false; frame.setState(JFrame.NORMAL); } } }); JButton btn = new JButton(); btn.setText("Btn"); final JPanel panel = new JPanel(); panel.add(btn); frame.add(panel); btn.addActionListener(e -> { programmatic = true; JOptionPane.showMessageDialog(panel, "Sample"); }); frame.setVisible(true); }
From source file:CutPasteSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cut/Paste Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); Action actions[] = textField.getActions(); Action cutAction = findAction(actions, DefaultEditorKit.cutAction); Action copyAction = findAction(actions, DefaultEditorKit.copyAction); Action pasteAction = findAction(actions, DefaultEditorKit.pasteAction); JPanel panel = new JPanel(); frame.add(panel, BorderLayout.SOUTH); JButton cutButton = new JButton(cutAction); cutButton.setText("Cut"); panel.add(cutButton);/*from w w w. j a v a 2s . c o m*/ JButton copyButton = new JButton(copyAction); copyButton.setText("Copy"); panel.add(copyButton); JButton pasteButton = new JButton(pasteAction); pasteButton.setText("Paste"); panel.add(pasteButton); frame.setSize(250, 250); frame.setVisible(true); }
From source file:CutPasteSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cut/Paste Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); JTextField textField = new JTextField(); JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); content.add(textField, BorderLayout.NORTH); content.add(scrollPane, BorderLayout.CENTER); Action actions[] = textField.getActions(); Action cutAction = TextUtilities.findAction(actions, DefaultEditorKit.cutAction); Action copyAction = TextUtilities.findAction(actions, DefaultEditorKit.copyAction); Action pasteAction = TextUtilities.findAction(actions, DefaultEditorKit.pasteAction); JPanel panel = new JPanel(); content.add(panel, BorderLayout.SOUTH); JButton cutButton = new JButton(cutAction); cutButton.setText("Cut"); panel.add(cutButton);//from w w w . j a va 2 s . c om JButton copyButton = new JButton(copyAction); copyButton.setText("Copy"); panel.add(copyButton); JButton pasteButton = new JButton(pasteAction); pasteButton.setText("Paste"); panel.add(pasteButton); frame.setSize(250, 250); frame.setVisible(true); }
From source file:Main.java
License:asdf
public static void main(String[] args) { JButton bn = new JButton("asdf"); bn.addPropertyChangeListener(new AbstractButtonPropertyChangeListener()); bn.setText("java2s.com"); JOptionPane.showMessageDialog(null, bn); }
From source file:Main.java
public static void main(String[] args) { JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); JButton button = new JButton(); Main f = null;/*from ww w. ja v a 2 s . c o m*/ f = new Main(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(700, 400); panel1.setLayout(new BorderLayout()); panel1.setForeground(Color.white); button.setText("Convert"); panel1.add(button, BorderLayout.SOUTH); f.setContentPane(panel1); f.setVisible(true); f1 = new Main(); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f1.setSize(457, 100); f1.setTitle("Conversion Progress"); f1.setLocationRelativeTo(null); panel2.setLayout(new BorderLayout()); panel2.setForeground(Color.white); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(35); progressBar.setStringPainted(true); panel2.add(progressBar, BorderLayout.SOUTH); f1.setContentPane(panel2); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { f1.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 .j av a2 s . 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); }