List of usage examples for javax.swing JFrame setLayout
public void setLayout(LayoutManager manager)
LayoutManager
. From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionFocusMover(); MouseListener mouseListener = new MouseEnterFocusMover(); frame.setLayout(new GridLayout(3, 3)); for (int i = 1; i < 10; i++) { JButton button = new JButton(Integer.toString(i)); button.addActionListener(actionListener); button.addMouseListener(mouseListener); if ((i % 2) != 0) { button.setFocusable(false);// www. j a v a 2s . c o m } frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
public static void main(String[] args) { JFrame frame = new JFrame("RedstoneLamp"); frame.setLayout(new GridLayout(2, 1)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JLabel label = new JLabel("RedstoneLamp"); label.setHorizontalAlignment(SwingConstants.CENTER); frame.add(label);/*from w w w . j a v a2 s . c om*/ JPanel lowPanel = new JPanel(); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); lowPanel.add(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); lowPanel.add(right); JButton openButton = new JButton("Open server at..."); openButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Select RedstoneLamp server home"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showOpenDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (!jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "Could not find RedstoneLamp installation. " + "Would you like to install RedstoneLamp there?"); if (result == JOptionPane.YES_OPTION) { installCallback(frame, selected); } return; } frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); } }); right.add(openButton); JButton installButton = new JButton("Install server at..."); installButton.addActionListener(e -> { JFileChooser chooser = new JFileChooser("."); chooser.setDialogTitle("Select directory to install server in"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); int action = chooser.showSaveDialog(frame); if (action == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); File jar = new File("RedstoneLamp.jar"); if (jar.isFile()) { int result = JOptionPane.showConfirmDialog(frame, "A RedstoneLamp jar installation is present. " + "Are you sure you want to reinstall RedstoneLamp there?"); if (result == JOptionPane.NO_OPTION) { frame.dispose(); addHistory(selected); currentRoot = new ServerActivity(selected); return; } } installCallback(frame, selected); } }); frame.add(lowPanel); frame.pack(); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dimension.width / 2 - frame.getSize().width / 2, dimension.height / 2 - frame.getSize().height / 2); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("JFrame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JButton counterButton = new JButton("Clicked #0"); JButton closeButton = new JButton("Close"); frame.setLayout(new FlowLayout()); contentPane.add(closeButton);// w w w . j av a 2s . c o m contentPane.add(counterButton); counterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { counterButton.setText("Clicked #" + counter++); } }); closeButton.addActionListener(e -> System.exit(0)); frame.pack(); frame.setVisible(true); }
From source file:com.moss.greenshell.wizard.catastrophe.PostMortemScreen.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setSize(800, 600);/*from www. j a v a 2s . c o m*/ final PostMortemScreen postMortemScreen = new PostMortemScreen( new Throwable("Just testing the PostMortemScreen")); final ProgressMonitorScreen progress = new ProgressMonitorScreen("Waiting for something to fail."); ProcessPanel processPanel = new ProcessPanel(progress); // postMortemScreen.setEnvironment(processPanel); frame.add(processPanel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); new Thread() { @Override public void run() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } progress.done(postMortemScreen); } }.start(); }
From source file:JFormattedTextFieldDateInputSampleDateFormatSHORT.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;// w ww. j a va 2 s . c om JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format shortDate = DateFormat.getDateInstance(DateFormat.SHORT); label = new JLabel("Short date:"); input = new JFormattedTextField(shortDate); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:JFormattedTextFieldDateInputSampleELocaleFRENCH.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;// www. j a va 2 s.co m JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format dayOfWeek = new SimpleDateFormat("E", Locale.FRENCH); label = new JLabel("French day of week:"); input = new JFormattedTextField(dayOfWeek); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:JFormattedTextFieldDateInputSampleDateFormatFULLLocaleUS.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;/*from w w w. j a va2 s.co m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format fullUSDate = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); label = new JLabel("Full US date:"); input = new JFormattedTextField(fullUSDate); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.add(new JTextField()); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textarea1 = new JTextArea(); Document document = textarea1.getDocument(); JTextArea textarea2 = new JTextArea(document); JTextArea textarea3 = new JTextArea(document); frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); frame.add(new JScrollPane(textarea1)); frame.add(new JScrollPane(textarea2)); frame.add(new JScrollPane(textarea3)); frame.setSize(300, 400);//from ww w .j a v a 2 s . c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Shared Model"); JTextArea areaFiftyOne = new JTextArea(); JTextArea areaFiftyTwo = new JTextArea(); areaFiftyTwo.setDocument(areaFiftyOne.getDocument()); JTextArea areaFiftyThree = new JTextArea(); areaFiftyThree.setDocument(areaFiftyOne.getDocument()); frame.setLayout(new GridLayout(3, 1)); frame.add(new JScrollPane(areaFiftyOne)); frame.add(new JScrollPane(areaFiftyTwo)); frame.add(new JScrollPane(areaFiftyThree)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300);//from ww w.j a v a2s. c o m frame.setVisible(true); }
From source file:MaskInputSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Mask Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;//from w w w . j a v a 2s .c o m JFormattedTextField input; JPanel panel; MaskFormatter formatter; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); try { label = new JLabel("SSN"); formatter = new MaskFormatter("###'-##'-####"); input = new JFormattedTextField(formatter); input.setValue("123-45-6789"); input.setColumns(20); panel = new JPanel(); panel.add(label); panel.add(input); frame.add(panel); } catch (ParseException e) { System.err.println("Unable to add SSN"); } frame.pack(); frame.setVisible(true); }