List of usage examples for javax.swing JFrame pack
@SuppressWarnings("deprecation") public void pack()
From source file:SelectionMonitor.java
public static void main(String s[]) { JFrame frame = new JFrame("Selection Monitor"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new SelectionMonitor()); frame.pack(); frame.setVisible(true);/*from w ww.ja va 2 s. com*/ }
From source file:Main.java
public static void main(String[] args) { String text = "one\ntwo\nthree\nfour\nfive"; JFrame frame = new JFrame("title"); JTextArea textArea = new JTextArea(text, 1, 30); // shows only one line JScrollPane scrollPane = new JScrollPane(textArea); frame.add(scrollPane);/*from www . ja v a 2 s . c o m*/ frame.pack(); frame.setVisible(true); final JViewport viewport = scrollPane.getViewport(); textArea.addCaretListener(e -> { System.out.println("First : " + viewport.getViewPosition()); System.out.println("Second: " + viewport.getViewPosition()); }); textArea.setCaretPosition(text.length()); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new JPanel() { @Override//from www. j a va 2 s .c o m public Dimension getPreferredSize() { return new Dimension(320, 240); } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = (int) rect.getMaxY() - f.getHeight(); f.setLocation(x, y); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); MyTextArea txt = new MyTextArea(); f.getContentPane().add(txt);/*w ww. ja va2s . c o m*/ f.getContentPane().add(new JButton("OK"), BorderLayout.SOUTH); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(4, 4)); ui.setBorder(new EmptyBorder(6, 6, 6, 6)); JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEADING)); ui.add(controls, BorderLayout.PAGE_START); int s = 100;/*from w w w . j a v a 2 s .c o m*/ Dimension[] sizes = { new Dimension(s * 4, s * 2), new Dimension(s * 6, s * 3), new Dimension(s * 8, s * 4) }; final JComboBox cb = new JComboBox(sizes); controls.add(cb); final JPanel[] panels = new JPanel[sizes.length]; for (int ii = 0; ii < sizes.length; ii++) { Dimension d = sizes[ii]; BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); JPanel p = new JPanel(new GridLayout()); JLabel l = new JLabel(new ImageIcon(bi)); p.add(l); panels[ii] = p; } ItemListener sizeListener = new ItemListener() { JPanel current = panels[0]; @Override public void itemStateChanged(ItemEvent e) { JPanel next = panels[cb.getSelectedIndex()]; swapComponentsAndResizeUI(ui, current, next); current = next; } }; cb.addItemListener(sizeListener); ui.add(panels[0], BorderLayout.CENTER); JFrame f = new JFrame("Three Sized Panels"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(ui); f.pack(); f.setLocationByPlatform(true); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new LoginPanel()); frame.pack(); frame.setVisible(true);/*from w w w . j a va 2 s . c om*/ }
From source file:TimeViewer.java
public static void main(String[] args) { JFrame f = new JFrame("Time Viewer"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new TimeViewer()); f.pack(); f.setVisible(true);//from w w w . jav a 2 s.c o m }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.add(new JPanel() { @Override/*w w w.j a v a2 s.c o m*/ public Dimension getPreferredSize() { return new Dimension(320, 240); } }); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = 0; f.setLocation(x, y); f.setVisible(true); }
From source file:FancyButton.java
public static void main(String[] args) { FancyButton b1 = new FancyButton(new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif")); FancyButton b2 = new FancyButton(new ImageIcon("4.gif"), new ImageIcon("1.gif"), new ImageIcon("2.gif")); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new FlowLayout()); c.add(b1);/*from ww w . ja va2 s. co m*/ c.add(b2); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DateFormatter[] formatters = new DateFormatter[] { new DateFormatter(new SimpleDateFormat("dd.MM.yyyy")), new DateFormatter(new SimpleDateFormat("ddMMyyyy")), new DateFormatter(new SimpleDateFormat("yyyy.MM.dd.")), new DateFormatter(new SimpleDateFormat("dd.MMM.yyyy")), new DateFormatter(new SimpleDateFormat("dd/MM/yyyy")) }; MultiFormatter<DateFormatter> multiFormatter = new MultiFormatter<>(formatters); JFormattedTextField ftf = new JFormattedTextField(multiFormatter); ftf.setColumns(10);// w w w. j a va2 s . co m JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(ftf); frame.add(new JButton("OK")); frame.pack(); frame.setVisible(true); }