Example usage for javax.swing JFrame setLayout

List of usage examples for javax.swing JFrame setLayout

Introduction

In this page you can find the example usage for javax.swing JFrame setLayout.

Prototype

public void setLayout(LayoutManager manager) 

Source Link

Document

Sets the LayoutManager.

Usage

From source file:XAxisAlignY.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = layoutComponents("Top", Component.TOP_ALIGNMENT);
    Container panel2 = layoutComponents("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = layoutComponents("Bottom", Component.BOTTOM_ALIGNMENT);

    frame.setLayout(new GridLayout(1, 3));
    frame.add(panel1);//from w w  w.  j  av  a2s  . c o m
    frame.add(panel2);
    frame.add(panel3);

    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:ActionButtonSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("DefaultButton");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String command = actionEvent.getActionCommand();
            System.out.println("Selected: " + command);
        }//from   ww  w. ja  v  a2  s .  c  o  m
    };
    frame.setLayout(new GridLayout(2, 2, 10, 10));
    JButton button1 = new JButton("Text Button");
    button1.setActionCommand("First");
    button1.addActionListener(actionListener);
    frame.add(button1);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:GraphPaperLayout.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setLayout(new GraphPaperLayout(new Dimension(5, 5)));
    // Add a 1x1 Rect at (0,0)
    frame.add(new Button("1"), new Rectangle(0, 0, 1, 1));
    // Add a 2x1 Rect at (2,0)
    frame.add(new Button("2"), new Rectangle(2, 0, 2, 1));
    // Add a 1x2 Rect at (1,1)
    frame.add(new Button("3"), new Rectangle(1, 1, 1, 2));
    // Add a 2x2 Rect at (3,2)
    frame.add(new Button("4"), new Rectangle(3, 2, 2, 2));
    // Add a 1x1 Rect at (0,4)
    frame.add(new Button("5"), new Rectangle(0, 4, 1, 1));
    // Add a 1x2 Rect at (2,3)
    frame.add(new Button("6"), new Rectangle(2, 3, 1, 2));
    frame.pack();//  w  w  w  .  j a  v  a 2 s.c  o  m
    frame.setVisible(true);

}

From source file:ua.com.fielden.platform.example.swing.schedule.ScheduleChartPanelExample.java

public static void main(final String[] args) {
    SwingUtilitiesEx.invokeLater(new Runnable() {

        @Override/* ww w.j  a  v a 2 s  . c o m*/
        public void run() {
            for (final LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(laf.getName())) {
                    try {
                        UIManager.setLookAndFeel(laf.getClassName());
                    } catch (final Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            com.jidesoft.utils.Lm.verifyLicense("Fielden Management Services", "Rollingstock Management System",
                    "xBMpKdqs3vWTvP9gxUR4jfXKGNz9uq52");
            LookAndFeelFactory.installJideExtension();
            final JFrame frame = new JFrame("Scedule chart demo");
            final JLabel label = new JLabel("None");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new MigLayout("fill, insets 0", "[grow, fill]", "[grow, fill][]"));
            frame.add(createScheduleChartPanel(label), "wrap");
            frame.add(label);
            frame.setPreferredSize(new Dimension(640, 480));
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:ua.com.fielden.platform.example.swing.booking.BookingChartPanelExample.java

public static void main(final String[] args) {
    SwingUtilitiesEx.invokeLater(new Runnable() {

        @Override/*  w w  w .  j av a2 s  . c  om*/
        public void run() {
            for (final LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(laf.getName())) {
                    try {
                        UIManager.setLookAndFeel(laf.getClassName());
                    } catch (final Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            com.jidesoft.utils.Lm.verifyLicense("Fielden Management Services", "Rollingstock Management System",
                    "xBMpKdqs3vWTvP9gxUR4jfXKGNz9uq52");
            LookAndFeelFactory.installJideExtension();
            final JFrame frame = new JFrame("Booking chart demo");
            final JLabel label = new JLabel("None");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new MigLayout("fill, insets 0", "[grow, fill]", "[grow, fill][]"));
            frame.add(createBookingChartPanel(label), "wrap");
            frame.add(label);
            frame.setPreferredSize(new Dimension(640, 480));
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    JOptionPane pane = new JOptionPane("Some message", JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION) {
        @Override//from  w  w w  .j a v a  2  s . c o  m
        public void setValue(Object newValue) {
            super.setValue(newValue);
            JOptionPane.showMessageDialog(frame.getContentPane(), "You have hit " + newValue);
        }
    };
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JLabel("Some panel in the middle"), BorderLayout.CENTER);
    frame.add(pane, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Main application entry point.//from  www .ja v  a2s .  c om
 * @param args
 *    The args - ignored.
 */
public static void main(String[] args) {

    final JFrame frame = new JFrame("TGAS HR diagram");

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            frame.add(new HrDiagram(), BorderLayout.CENTER);
            frame.setSize(1500, 750);
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:flow.visibility.FlowMain.java

public static void main(String[] args) throws Exception {

    /************************************************************** 
     * Creating the Main GUI /*from  w  w  w  .  j a  v a2s . c  o  m*/
     **************************************************************/

    final JDesktopPane desktop = new JDesktopPane();

    final JMenuBar mb = new JMenuBar();
    JMenu menu;

    /** Add File Menu to Open File and Save Result */

    menu = new JMenu("File");
    JMenuItem Open = new JMenuItem("Open");
    JMenuItem Save = new JMenuItem("Save");
    menu.add(Open);
    menu.add(Save);

    menu.addSeparator();
    JMenuItem Exit = new JMenuItem("Exit");
    menu.add(Exit);
    Exit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });

    mb.add(menu);

    /** Add Control Menu to Start and Stop Capture */

    menu = new JMenu("Control");
    JMenuItem Start = new JMenuItem("Start Capture");
    JMenuItem Stop = new JMenuItem("Stop Capture");
    menu.add(Start);
    Start.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FlowDumper.main(false);
        }
    });

    menu.add(Stop);
    Stop.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FlowDumper.main(true);
        }
    });

    mb.add(menu);

    /** Add Configuration Menu for Tapping and Display */

    menu = new JMenu("Configuration");
    JMenuItem Tapping = new JMenuItem("Tapping Configuration");
    JMenuItem Display = new JMenuItem("Display Configuration");
    menu.add(Tapping);
    Tapping.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FlowTapping.main(null);
        }
    });
    menu.add(Display);

    mb.add(menu);

    /** Add Detail Menu for NetGrok Visualization and JEthereal Inspection */

    menu = new JMenu("Flow Detail");
    JMenuItem FlowVisual = new JMenuItem("Flow Visualization");
    JMenuItem FlowInspect = new JMenuItem("Flow Inspections");
    menu.add(FlowVisual);
    FlowVisual.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            NetworkView.main(null);
        }
    });
    menu.add(FlowInspect);
    FlowInspect.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Ethereal.main(null);
        }
    });
    mb.add(menu);

    /** Add Help Menu for Software Information */
    menu = new JMenu("Help");
    JMenuItem About = new JMenuItem("About");
    menu.add(About);
    About.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "OF@TEIN Flow Visibility Tools @ 2015 by GIST",
                    "About the Software", JOptionPane.PLAIN_MESSAGE);
        }
    });
    mb.add(menu);

    /** Creating the main frame */
    JFrame frame = new JFrame("OF@TEIN Flow Visibility Tools");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(desktop);
    frame.setJMenuBar(mb);
    frame.setSize(1215, 720);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    /**Add Blank three (3) Internal Jframe*/

    /**Internal Frame from Flow Summary Chart*/
    JInternalFrame FlowStatistic = new JInternalFrame("Flow Statistic", true, true, true, true);
    FlowStatistic.setBounds(0, 0, 600, 330);
    ChartPanel chartPanel = new ChartPanel(createChart(null));
    chartPanel.setMouseZoomable(true, false);
    FlowStatistic.add(chartPanel);
    FlowStatistic.setVisible(true);
    desktop.add(FlowStatistic);

    /**Internal Frame from Flow Summary Text*/
    JInternalFrame FlowSummary = new JInternalFrame("Flow Summary", true, true, true, true);
    FlowSummary.setBounds(0, 331, 600, 329);
    JTextArea textArea = new JTextArea(50, 10);
    JScrollPane scrollPane = new JScrollPane(textArea);
    FlowSummary.add(scrollPane);
    FlowSummary.setVisible(true);
    desktop.add(FlowSummary);

    //JInternalFrame FlowInspection = new JInternalFrame("Flow Inspection", true, true, true, true);
    //FlowInspection.setBounds(601, 0, 600, 660);
    //JTextArea textArea2 = new JTextArea(50, 10);
    //JScrollPane scrollPane2 = new JScrollPane(textArea2);
    //FlowInspection.add(scrollPane2);
    //FlowInspection.setVisible(true);
    //desktop.add(FlowInspection);

    /**Internal Frame from Printing the Packet Sequence*/
    JInternalFrame FlowSequence = new JInternalFrame("Flow Sequence", true, true, true, true);
    FlowSequence.setBounds(601, 0, 600, 660);
    JTextArea textArea3 = new JTextArea(50, 10);
    JScrollPane scrollPane3 = new JScrollPane(textArea3);
    FlowSequence.add(scrollPane3);
    FlowSequence.setVisible(true);
    desktop.add(FlowSequence);

    /************************************************************** 
     * Update the Frame Regularly
     **************************************************************/

    /** Regularly update the Frame Content every 3 seconds */

    for (;;) {

        desktop.removeAll();
        desktop.add(FlowProcess.FlowStatistic());
        desktop.add(FlowProcess.FlowSummary());
        //desktop.add(FlowProcess.FlowInspection());
        desktop.add(FlowProcess.FlowSequence());
        desktop.revalidate();
        Thread.sleep(10000);

    }

}

From source file:projects.upc.exec.HrDiagram.java

/**
 * Main application entry point.// w w w. ja v a 2s . co  m
 * @param args
 *    The args - ignored.
 */
public static void main(String[] args) {

    final JFrame frame = new JFrame("UPC HR diagram");

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            frame.add(new HrDiagram(), BorderLayout.CENTER);
            frame.setSize(1500, 750);
            frame.pack();
            frame.setVisible(true);
        }
    });
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Main application entry point.//from   ww w  .ja  v  a 2s  .  com
 * @param args
 *    The args - ignored.
 */
public static void main(String[] args) {

    final JFrame frame = new JFrame("Hipparcos HR diagram");

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            frame.add(new HrDiagram(), BorderLayout.CENTER);
            frame.setSize(1500, 750);
            frame.pack();
            frame.setVisible(true);
        }
    });
}