protected JPanel createStatusArea() { JPanel statusArea = new JPanel(); JLabel status = new JLabel("No log records to display."); _statusLabel = status; status.setHorizontalAlignment(JLabel.LEFT); statusArea.setBorder(BorderFactory.createEtchedBorder()); statusArea.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); statusArea.add(status); return (statusArea); }
private void initAboutBox() { aboutBox = new JDialog(this, "About Tregex"); aboutBox.getContentPane().setLayout(new BorderLayout()); aboutBox.getContentPane().add(new JLabel("<html><b>Tregex and Tsurgeon</b></html>", SwingConstants.CENTER), BorderLayout.NORTH); aboutBox.getContentPane().add(new JLabel("<html>Tregex by Galen Andrew and Roger Levy<br>Tsurgeon by Roger Levy<br>Graphical interface by Anna Rafferty<br>Additional features and development by Chris Manning<br></html>", SwingConstants.CENTER), BorderLayout.CENTER); aboutBox.getContentPane().add(new JLabel("<html><font size=2>\u00A92007 The Board of Trustees of The Leland Stanford Junior University.<br>Distributed under the GNU General Public License</font></html>", SwingConstants.CENTER), BorderLayout.SOUTH); }
import javax.swing.JFrame; import javax.swing.JLabel; public class AnotherJFrame extends JFrame { public AnotherJFrame() { super("Another GUI"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(new JLabel("Empty JFrame")); pack(); setVisible(true); } }
import javax.swing.*; public class JOptionPaneMultiInput { public static void main(String[] args) { JTextField xField = new JTextField(5); JTextField yField = new JTextField(5); JPanel myPanel = new JPanel(); myPanel.add(new JLabel("x:")); myPanel.add(xField); myPanel.add(Box.createHorizontalStrut(15)); // a spacer myPanel.add(new JLabel("y:")); myPanel.add(yField); int result = JOptionPane.showConfirmDialog(null, myPanel, "Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { System.out.println("x value: " + xField.getText()); System.out.println("y value: " + yField.getText()); } } }
public void afterPropertiesSet() throws Exception { ClassPathResource resource = new ClassPathResource("logo.png"); ImageIcon icon = new ImageIcon(resource.getURL()); JLabel logo = new JLabel(icon); refreshButton.addActionListener(this); JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); valuePanel.add(valueField); valuePanel.add(saveButton); secureMethod3Button.addActionListener(this); JPanel methodPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); methodPanel.add(secureMethod1Button); methodPanel.add(secureMethod2Button); methodPanel.add(secureMethod3Button); 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 static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new GridBagLayout()); JPanel panel = new JPanel(); panel.add(new JLabel("This is a label")); panel.setBorder(new LineBorder(Color.BLACK)); // make it easy to see frame.add(panel, new GridBagConstraints()); frame.setSize(400, 400); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
JPanel content = new JPanel(); content.setLayout(new FlowLayout()); content.add(new JLabel("Input")); content.add(m_userInputTf); content.add(m_multiplyBtn); content.add(new JLabel("Total")); content.add(m_totalTf); content.add(m_clearBtn); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/** * show the image as JFrame on desktop */ public void show() { JLabel label = new JLabel(new ImageIcon(this.image)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(label); f.pack(); f.setVisible(true); }
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"); } }); }}); }}); }};
append("the available space</html>"); JLabel label = new JLabel(sb.toString()); JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(label);
label1 = new JLabel("max 10 chars"); textfield1 = new JTextField(15); add(label1); add(textfield1); textfield1.setDocument(new JTextFieldLimit(10)); setVisible(true);
$cat HelloWorldSwing.java package start; import javax.swing.*; public class HelloWorldSwing { public static void main(String[] args) { //Create and set up the window. JFrame frame = new JFrame("HelloWorldSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hello World"); frame.add(label); //Display the window. frame.pack(); frame.setVisible(true); } } class Dummy { // just to have another thing to pack in the jar }
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); }
return; final JFrame exceptionFrame = new JFrame("Uncaught exception: " + e.getMessage()); Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon"); BufferedImage errorImage = new BufferedImage( errorIcon.paintIcon(null, errorImage.getGraphics(), 0, 0); exceptionFrame.setIconImage(errorImage); exceptionFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel contentPanel = new JPanel(new BorderLayout(5, 5)); contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); contentPanel.add(new JLabel("An uncaught exception has occurred: "), BorderLayout.NORTH); JTextArea stackTraceTextArea = new JTextArea(30, 80); stackTraceTextArea.setEditable(false); contentPanel.add(stackTraceScrollPane, BorderLayout.CENTER); stackTraceTextArea.setCaretPosition(0); // Scroll to top JPanel buttonPanel = new JPanel(new GridLayout(1, 0)); JButton closeButton = new JButton(new AbstractAction("Close") { @Override
public Splash (Frame frame, String imageFile, int minMillis) { super(frame); this.minMillis = minMillis; getContentPane().add(new JLabel(new ImageIcon(Splash.class.getResource(imageFile))), BorderLayout.CENTER); pack(); setLocationRelativeTo(null); setVisible(true); startTime = System.currentTimeMillis(); }
/** * show the images as stream of JFrame on desktop */ public void show() { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); JLabel label = null; while (true) { for (int i = 0; i < this.frames.size(); i++) { Frame frame = this.frames.get(i); if (label == null) { label = new JLabel(new ImageIcon(frame.image)); f.getContentPane().add(label); f.pack(); } else { label.getGraphics().drawImage(frame.image,0,0, label); } try {Thread.sleep(frame.delayMillis);} catch (InterruptedException e) {} } } } }
JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setSize(200, 200); // create the status bar panel and shove it down the bottom of the frame JPanel statusPanel = new JPanel(); statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED)); frame.add(statusPanel, BorderLayout.SOUTH); statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16)); statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); JLabel statusLabel = new JLabel("status"); statusLabel.setHorizontalAlignment(SwingConstants.LEFT); statusPanel.add(statusLabel); frame.setVisible(true);
private static void init() { if (frame != null) frame.setVisible(false); frame = new JFrame(); offscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); onscreenImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); JLabel draw = new JLabel(icon); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // closes all windows