private void makeGUI() { final JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().setLayout(new FlowLayout()); // include: "class AnswerWorker" code here. // include: "JButton" b code here. f.getContentPane().add(b); f.getContentPane().add(new JButton("Nothing")); f.pack(); f.setVisible(true); }
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setTitle("Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton(); button.setText("Hello, World!"); frame.getContentPane().add(button, BorderLayout.CENTER); frame.setSize(200, 100); frame.pack(); frame.setVisible(true); frame.show(); } }
JFrame frame = new JFrame(){{ add( new JPanel(){{ add( new JLabel("Hey there"){{ setBackground(Color.black); setForeground( Color.white); }}); add( new JButton("Ok"){{ addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent ae ){ System.out.println("Button pushed"); } }); }}); }}); }};
import java.awt.event.*; import javax.swing.*; public class YourDialog extends JDialog implements ActionListener { JButton button; public YourDialog() { button = new JButton("Close"); button.addActionListener(this); add(button); pack(); setVisible(true); } public void actionPerformed(ActionEvent e) { dispose(); } }
updateValueLabel(); saveButton = new JButton("Save Value"); saveButton.addActionListener(this); refreshButton = new JButton("Refresh Value"); refreshButton.addActionListener(this); JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); valuePanel.add(valueField); valuePanel.add(saveButton); valuePanel.add(refreshButton); secureMethod1Button = new JButton("Method #1"); secureMethod1Button.addActionListener(this); secureMethod2Button = new JButton("Method #2"); secureMethod2Button.addActionListener(this); secureMethod3Button = new JButton("Method #3"); secureMethod3Button.addActionListener(this); frame = new JFrame("Apache Shiro Sample Application"); frame.setSize(500, 200); panel.add(logo, BorderLayout.NORTH); panel.add(valuePanel, BorderLayout.CENTER); panel.add(methodPanel, BorderLayout.SOUTH);
public LogFactor5ErrorDialog(JFrame jframe, String message) { super(jframe, "Error", true); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); JPanel bottom = new JPanel(); bottom.setLayout(new FlowLayout()); bottom.add(ok); JPanel main = new JPanel(); main.setLayout(new GridBagLayout()); wrapStringOnPanel(message, main); getContentPane().add(main, BorderLayout.CENTER); getContentPane().add(bottom, BorderLayout.SOUTH); show(); } //--------------------------------------------------------------------------
protected void initComponents() { Panel buttonPanel = new Panel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton okButton = new JButton(LocalisationHelper.getString("button_ok")); okButton.setActionCommand(ACTION_OK); okButton.addActionListener(this); buttonPanel.add(okButton); getContentPane().add("South", buttonPanel); }
JFrame frame = new JFrame("test"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(4,4,4,4)); for(int i=0 ; i<16 ; i++){ JButton btn = new JButton(String.valueOf(i)); btn.setPreferredSize(new Dimension(40, 40)); panel.add(btn); } frame.setContentPane(panel); frame.pack(); frame.setVisible(true);
final JFrame frame = new JFrame("Display Mode"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setUndecorated(true); JButton btn1 = new JButton("Full-Screen"); btn1.addActionListener(new ActionListener() { @Override JButton btn2 = new JButton("Normal"); btn2.addActionListener(new ActionListener() { @Override JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER)); panel.add(btn1); panel.add(btn2);
private void createView() { JPanel controlsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); serverTextField = new JTextField(""); serverTextField.setColumns(15); serverTextField.selectAll(); JPanel textPanel = new JPanel(new GridLayout(4, 2, 0, 10)); textPanel.add(new JLabel("Go Server Hostname or IP")); textPanel.add(serverTextField); textPanel.add(new JLabel("SSL Mode")); sslModeComponent = new SslModeComponent(); textPanel.add(sslModeComponent); textPanel.add(new JLabel("Server root certificate")); fileBrowser = new FileBrowser(); textPanel.add(fileBrowser); controlsPanel.add(textPanel); getContentPane().add(controlsPanel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10)); okButton = new JButton("OK"); buttonPanel.add(okButton); getContentPane().add(buttonPanel, BorderLayout.SOUTH); }
private JComponent getSouthLabel() { final JPanel result = new JPanel(); final JButton license = new JButton("License"); license.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new LicenseWindow(); } }); final JButton ok = new JButton("OK"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); } }); result.add(license); result.add(ok); return result; }
public RouteDialog(JFrame owner, String initialFrom) { super(owner, true); fromField = new JTextField(initialFrom, 30); toField = new JTextField(30); goButton = new JButton("Go"); Container pane = getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); pane.add(new JLabel("From")); pane.add(fromField); pane.add(new JLabel("To")); pane.add(toField); pane.add(goButton); pack(); final RouteDialog outer = this; goButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { from = fromField.getText().trim(); to = toField.getText().trim(); outer.setVisible(false); } }); setVisible(true); } }
JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); JPanel firstPanel = new JPanel(); firstPanel.setLayout(new GridLayout(4, 4)); firstPanel.setMaximumSize(new Dimension(400, 400)); for (int i=1; i<=4; i++) { for (int j=1; j<=4; j++) { btn = new JButton(); btn.setPreferredSize(new Dimension(100, 100)); firstPanel.add(btn); JPanel secondPanel = new JPanel(); secondPanel.setLayout(new GridLayout(5, 13)); secondPanel.setMaximumSize(new Dimension(520, 200)); for (int i=1; i<=5; i++) { for (int j=1; j<=13; j++) { btn = new JButton(); btn.setPreferredSize(new Dimension(40, 40)); secondPanel.add(btn);
super(jframe, title, true); JPanel bottom = new JPanel(); bottom.setLayout(new FlowLayout()); JPanel main = new JPanel(); main.setLayout(new FlowLayout()); main.add(new JLabel(label)); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().add(main, BorderLayout.CENTER); getContentPane().add(bottom, BorderLayout.SOUTH); pack(); centerWindow(this);
private JPanel makeTSurgeonButtons() { JPanel tsurgeonButtonBox = new JPanel(); tsurgeonButtonBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); tsurgeonButtonBox.setLayout(new GridBagLayout()); tsurgeonHelp = new JButton("Help"); tsurgeonHelp.addActionListener(this); cancelTsurgeon = new JButton("Cancel"); cancelTsurgeon.addActionListener(this); runScript = new JButton("Run script"); runScript.addActionListener(this); //make constraints and add in GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHEAST; c.fill = GridBagConstraints.HORIZONTAL; tsurgeonButtonBox.add(runScript,c); tsurgeonButtonBox.add(cancelTsurgeon,c); tsurgeonButtonBox.add(tsurgeonHelp,c); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; c.weighty = 1.0; tsurgeonButtonBox.add(new JLabel(), c); return tsurgeonButtonBox; } //separated out to make constructor more readable
public GoodlyOverridenAdapterTest() { addWindowListener(new WindowAdapter() { @NoWarning("BOA") public void windowClosing() { dispose(); System.exit(0); } @Override @NoWarning("BOA") public void windowClosing(WindowEvent we) { windowClosing(); } }); Container cp = getContentPane(); cp.add(new JButton("Click Me")); } }