List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:SimpleDnD.java
public static void main(String[] args) { JTextField field = new JTextField(10); JButton button = new JButton("Button"); JFrame f = new JFrame(); f.setTitle("Simple Drag & Drop"); f.setLayout(new FlowLayout()); f.add(button);/* ww w . j av a 2 s.co m*/ f.add(field); field.setDragEnabled(true); button.setTransferHandler(new TransferHandler("text")); f.setSize(330, 150); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.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 www .j a va 2 s . c om frame.add(new JButton("1")); frame.add(new JButton("2")); gbl.layoutContainer(frame); gbl.columnWeights = new double[] { 0.0f, 1.0f, 2.0f }; gbl.rowWeights = new double[] { 0.0f, 1.0f }; frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JButton btn = new JButton("Test"); JPanel panel = new JPanel(); panel.add(btn);//from w ww .ja v a 2s . c o m JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.add("Tab1", panel); frame.add(tabbedPane, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setMinimumSize(new Dimension(300, 300)); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JToolBar toolbar = new JToolBar(JToolBar.VERTICAL); JButton selectb = new JButton(new ImageIcon("select.gif")); JButton freehandb = new JButton(new ImageIcon("freehand.gif")); JButton shapeedb = new JButton(new ImageIcon("shapeed.gif")); JButton penb = new JButton(new ImageIcon("pen.gif")); toolbar.add(selectb);/*from www . ja v a 2 s. c o m*/ toolbar.add(freehandb); toolbar.add(shapeedb); toolbar.add(penb); JFrame f = new JFrame(); f.add(toolbar, BorderLayout.WEST); f.setSize(250, 350); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Add a close button JButton closeButton = new JButton("Close"); Container contentPane = frame.getContentPane(); contentPane.add(closeButton);/*from w ww. j a v a2 s .c o m*/ // Calculates and sets appropriate size for the frame frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JColorChooser Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton("Pick to Change Background"); Color myBlack = new Color(0, 0, 0); // Color black // Color myWhite = new Color(255,255,255); // Color white // Color myGreen = new Color(0,200,0); // A shade of green button.setBackground(myBlack);/*from w w w. j av a 2s.c om*/ f.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.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 . ja v a2s .c o m frame.add(new JButton("1")); frame.add(new JButton("2")); gbl.layoutContainer(frame); double[][] weights = gbl.getLayoutWeights(); for (int i = 0; i < 2; i++) { for (int j = 0; j < weights[i].length; j++) { weights[i][j] = 1; } } gbl.columnWeights = weights[0]; gbl.rowWeights = weights[1]; frame.pack(); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JFrame f = new JFrame(); final JPanel p1 = new JPanel(); p1.add(new JLabel("GlassPane Example")); JButton show = new JButton("Show"); p1.add(show);// w ww . j a va2s .c o m p1.add(new JButton("No-op")); f.getContentPane().add(p1); final JPanel glass = (JPanel) f.getGlassPane(); glass.setVisible(true); glass.setLayout(new GridBagLayout()); JButton glassButton = new JButton("Hide"); glass.add(glassButton); f.setSize(150, 80); f.setVisible(true); show.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { glass.setVisible(true); p1.repaint(); } }); glassButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { glass.setVisible(false); p1.repaint(); } }); }
From source file:DrivedFont.java
public static void main(String args[]) { JFrame f = new JFrame("JColorChooser Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton("Pick to Change Background"); Font myFont = new Font("Serif", Font.ITALIC | Font.BOLD, 12); Font newFont = myFont.deriveFont(50F); button.setFont(newFont);//from w w w . ja va 2 s. c o m f.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JButton jb = new JButton("Press Me"); jb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { System.out.println("ItemEvent!"); }/*w w w. ja va 2 s . c o m*/ }); jb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ev) { System.out.println("ChangeEvent!"); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }