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(Main.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton("Click me to open dialog"); button.addActionListener(e -> {//from w ww . j a va 2s. c o m Window parentWindow = SwingUtilities.windowForComponent(button); JDialog dialog = new JDialog(parentWindow); dialog.setLocationRelativeTo(button); dialog.setModal(true); dialog.add(new JLabel("A dialog")); dialog.pack(); dialog.setVisible(true); }); frame.add(button); frame.pack(); frame.setVisible(true); }
From source file:ABevelBorder.java
public static void main(String args[]) { JFrame frame = new JFrame("Bevel Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = BorderFactory.createRaisedBevelBorder(); JButton button = new JButton("Raised"); button.setBorder(raisedBorder);/* w w w .j av a 2 s . c o m*/ frame.add(button); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JFrame f = new JFrame(); f.setLayout(new BorderLayout()); JPanel panel = new JPanel(); JButton button = new JButton("A-ha!"); button.setAlignmentX(Component.CENTER_ALIGNMENT); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.add(Box.createVerticalGlue()); panel.add(button);// www .j av a 2s .co m panel.add(Box.createVerticalGlue()); f.getContentPane().add(panel); f.setVisible(true); }
From source file:PaneInsertionMethods.java
public static void main(String[] args) { final JTextPane pane = new JTextPane(); pane.replaceSelection("text"); pane.insertIcon(new ImageIcon("imageName.gif")); pane.insertComponent(new JButton("Click Me")); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(pane, BorderLayout.CENTER); frame.setSize(360, 180);//w ww . jav a 2s. com frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JProgressBar progressBar = new JProgressBar(); JButton button = new JButton("Start"); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(progressBar);/*from w w w . j a v a2 s . co m*/ f.add(button); ActionListener updateProBar = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int val = progressBar.getValue(); if (val >= 100) { // timer.stop(); button.setText("End"); return; } progressBar.setValue(++val); } }; Timer timer = new Timer(50, updateProBar); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (timer.isRunning()) { timer.stop(); button.setText("Start"); } else if (button.getText() != "End") { timer.start(); button.setText("Stop"); } } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static final void main(String[] args) { JFrame frame = new JFrame(); JTabbedPane tabbedPane = new JTabbedPane(); frame.add(tabbedPane);//from w ww . j av a 2s.c o m JButton addButton = new JButton("Add tab"); addButton.addActionListener(e -> { JPanel newTabComponent = new JPanel(); int tabCount = tabbedPane.getTabCount(); newTabComponent.add(new JLabel("I'm tab " + tabCount)); tabbedPane.addTab("Tab " + tabCount, newTabComponent); }); frame.add(addButton, BorderLayout.SOUTH); addButton.doClick(); frame.setSize(800, 300); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setVisible(true); }
From source file:HTMLButton.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>" + "<font color=\"#FF0080\"><u>Multi-line</u></font>"; JButton button4 = new JButton(htmlButton); frame.add(button4);//from w w w. j a v a 2 s .c o m frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolBar = new JToolBar("Still draggable"); toolBar.setFloatable(false);/* ww w .ja v a 2s . co m*/ toolBar.setRollover(true); toolBar.add(new JButton("New")); toolBar.addSeparator(); toolBar.add(new JButton("Open")); frame.add(toolBar, "North"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JPanel panel2 = new JPanel(new BorderLayout()); panel2.add(new JButton("NORTH"), BorderLayout.NORTH); panel2.add(new JButton("CENTER")); panel.add(panel2);/*w w w . j a va2 s . c o m*/ panel.add(new JButton("SOUTH"), BorderLayout.SOUTH); panel.add(new JButton("EAST"), BorderLayout.EAST); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JFrame frame = new JFrame(); GridBagLayout gbl = new GridBagLayout(); frame.setLayout(gbl);//from w w w .j a va 2 s .c o m JButton component = new JButton("1"); frame.add(new JButton("2")); frame.add(new JButton("3")); frame.add(new JButton("4")); frame.add(new JButton("5")); frame.add(component); frame.add(new JButton("6")); frame.add(new JButton("7")); frame.add(new JButton("8")); frame.add(new JButton("9")); frame.add(new JButton("0")); gbl.layoutContainer(frame); GridBagConstraints gbc = new GridBagConstraints(); int top = 20; int left = 20; int bottom = 2; int right = 40; gbc.insets = new Insets(top, left, bottom, right); gbl.setConstraints(component, gbc); frame.pack(); frame.setVisible(true); }