List of usage examples for javax.swing JFrame JFrame
public JFrame() throws HeadlessException
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("First Name"); label.setForeground(Color.lightGray); JFrame frame = new JFrame(); frame.add(label);//from w w w. j a v a 2 s . com frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(20, 20, 500, 500); frame.setVisible(true); }
From source file:BoxLayoutDemo.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); LayoutManager layout = new BoxLayout(panel, BoxLayout.X_AXIS); panel.setLayout(layout);//from w ww. j a v a2 s .com panel.add(new JLabel("a")); panel.add(new JLabel("b")); panel.add(new JLabel("c")); panel.add(new JLabel("d")); panel.add(new JLabel("e")); panel.add(new JLabel("f")); frame.add(panel); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.setBorderPainted(false);//w w w . j ava 2 s . c om JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("First Name"); label.setForeground(Color.LIGHT_GRAY); JFrame frame = new JFrame(); frame.add(label);/* w w w.j a v a 2s . c om*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(20, 20, 500, 500); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);//from ww w.j a va 2 s . c o m System.out.println(layout.getLayoutStyle()); JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);//from www . ja va 2 s .co m System.out.println(layout.getAutoCreateGaps()); JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);/* w w w. ja v a 2 s . c o m*/ System.out.println(layout.getHonorsVisibility()); JButton buttonD = new JButton("D"); JButton buttonR = new JButton("R"); JButton buttonY = new JButton("Y"); JButton buttonO = new JButton("O"); JButton buttonT = new JButton("T"); GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup(); leftToRight.addComponent(buttonD); GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup(); columnMiddle.addComponent(buttonR); columnMiddle.addComponent(buttonO); columnMiddle.addComponent(buttonT); leftToRight.addGroup(columnMiddle); leftToRight.addComponent(buttonY); GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup(); GroupLayout.ParallelGroup rowTop = layout.createParallelGroup(); rowTop.addComponent(buttonD); rowTop.addComponent(buttonR); rowTop.addComponent(buttonY); topToBottom.addGroup(rowTop); topToBottom.addComponent(buttonO); topToBottom.addComponent(buttonT); layout.setHorizontalGroup(leftToRight); layout.setVerticalGroup(topToBottom); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(200, 200);//from ww w . ja v a 2 s .co m frame.setVisible(true); JOptionPane.showMessageDialog(frame, "A"); JOptionPane.showMessageDialog(frame, "B", "message", JOptionPane.WARNING_MESSAGE); int result = JOptionPane.showConfirmDialog(null, "Remove now?"); switch (result) { case JOptionPane.YES_OPTION: System.out.println("Yes"); break; case JOptionPane.NO_OPTION: System.out.println("No"); break; case JOptionPane.CANCEL_OPTION: System.out.println("Cancel"); break; case JOptionPane.CLOSED_OPTION: System.out.println("Closed"); break; } String name = JOptionPane.showInputDialog(null, "Please enter your name."); System.out.println(name); JTextField userField = new JTextField(); JPasswordField passField = new JPasswordField(); String message = "Please enter your user name and password."; result = JOptionPane.showOptionDialog(frame, new Object[] { message, userField, passField }, "Login", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) System.out.println(userField.getText() + " " + new String(passField.getPassword())); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(400, 400);/* w w w .ja va 2 s .c om*/ frame.setVisible(true); String[] list = { "1", "2", "3", "4", }; JComboBox<String> comb = new JComboBox<>(list); final JPopupMenu pop = new JPopupMenu(); pop.add(comb); frame.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { System.out.println("mousePressed"); pop.show(e.getComponent(), e.getX(), e.getY()); } }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); JFrame window = new JFrame(); window.setSize(300, 300);/*from w w w . j a v a2 s. c om*/ int w = window.getSize().width; int h = window.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; window.setLocation(x, y); window.setVisible(true); }