List of usage examples for javax.swing JFrame pack
@SuppressWarnings("deprecation") public void pack()
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane = new JTabbedPane(); for (int i = 0; i < 5; i++) { tabbedPane.add("Tab " + i, new JLabel("Label " + i, SwingConstants.CENTER)); }/*from w w w. j a va 2 s .c o m*/ tabbedPane.getModel().addChangeListener(e -> { JLabel label = (JLabel) tabbedPane.getSelectedComponent(); System.out.println(label.getText()); }); tabbedPane.setPreferredSize(new Dimension(500, 300)); JFrame frame = new JFrame(); frame.getContentPane().add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { //Read from an input stream InputStream is = new BufferedInputStream(new FileInputStream("source.gif")); Image image = ImageIO.read(is); JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label, BorderLayout.CENTER); frame.pack(); frame.setVisible(true);//from w w w .j a va2s .c om }
From source file:Main.java
public static void main(String[] argv) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add("Center", new Main()); frame.pack(); frame.setVisible(true);//w ww . ja v a 2s . c o m }
From source file:Main.java
public static void main(String[] args) { JLabel label = new JLabel("Hello"); label.setOpaque(true);//w ww. j av a2 s . com label.setBackground(Color.red); JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.add(label, BorderLayout.LINE_END); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); mainPanel.setPreferredSize(new Dimension(400, 400)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Hello!!"); frame.setAlwaysOnTop(true);/*from w w w . j a v a 2s .c o m*/ frame.setLocationByPlatform(true); frame.add(new JLabel(" Always visible")); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String s[]) { JFrame frame = new JFrame("Slider Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new Main()); frame.pack(); frame.setVisible(true);/*from w ww . ja v a2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { Main temp = new Main(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(temp);// ww w . ja v a 2 s .com frame.pack(); frame.setVisible(true); Thread updater = new Thread(temp.new CustomThread()); updater.start(); }
From source file:Main.java
public static void main(String[] args) { JButton btnA = new JButton("A"); JButton btnB = new JButton("B"); btnA.setPreferredSize(new Dimension(50, 25)); btnB.setPreferredSize(new Dimension(100, 25)); JPanel btnAPanel = new JPanel(); JPanel btnBPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); btnAPanel.add(btnA);//from w ww . j a v a2 s . c o m btnBPanel.add(btnB); JPanel topPanel = new JPanel(new GridLayout(1, 0)); topPanel.add(new JLabel("hi")); topPanel.add(btnAPanel); topPanel.add(btnBPanel); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(topPanel, BorderLayout.NORTH); mainPanel.setPreferredSize(new Dimension(400, 300)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(mainPanel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws IOException { BufferedImage original = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage rotated1 = create(original, -Math.PI / 2, gc); BufferedImage rotated2 = create(original, +Math.PI / 4, gc); BufferedImage rotated3 = create(original, Math.PI, gc); JPanel cp = new JPanel(); cp.add(new JLabel(new ImageIcon(original))); cp.add(new JLabel(new ImageIcon(rotated1))); cp.add(new JLabel(new ImageIcon(rotated2))); cp.add(new JLabel(new ImageIcon(rotated3))); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(cp);/*from ww w . java 2 s. co m*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JProgressBar pb = new JProgressBar(0, 100); ReadFileWorker worker = new ReadFileWorker(); worker.addPropertyChangeListener(new PropertyChangeListener() { @Override/*from w ww. ja v a 2 s .com*/ public void propertyChange(PropertyChangeEvent evt) { if ("progress".equalsIgnoreCase(evt.getPropertyName())) { pb.setValue(worker.getProgress()); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(pb); f.pack(); f.setVisible(true); worker.execute(); }