Example usage for javax.swing JPanel setLayout

List of usage examples for javax.swing JPanel setLayout

Introduction

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

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:org.xapagy.ui.tempdyn.tdVisualizationGenerator.java

/**
 * Generate a vertical list of JFreeCharts
 * //from w  w w  .ja  v  a2 s.  c  o m
 * @param labels
 *            - the labels for the values
 * @param index
 *            - the index
 * @param values
 * @return
 */
public static String generateJFreeChart(List<String> labels, List<Double> index, List<List<Double>> values) {
    JPanel panel = new JPanel();
    // create a layout
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    SequentialGroup sgv = layout.createSequentialGroup();
    layout.setVerticalGroup(sgv);
    ParallelGroup pgh = layout.createParallelGroup();
    layout.setHorizontalGroup(pgh);
    for (int i = 0; i != labels.size(); i++) {
        XYSeries xys = new XYSeries(labels.get(i));
        for (int j = 0; j != index.size(); j++) {
            xys.add(index.get(j), values.get(i).get(j));
        }
        XYSeriesCollection xysc = new XYSeriesCollection(xys);
        JFreeChart chart = ChartFactory.createXYLineChart(labels.get(i), "Time", "Focus", xysc,
                PlotOrientation.VERTICAL, false, false, false);
        chart.setBackgroundPaint(Color.white);
        chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14));
        ChartPanel cp = new ChartPanel(chart);
        sgv.addComponent(cp);
        pgh.addComponent(cp);
    }
    JFrame frame = new JFrame();
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
    return null;
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static JComponent createTitledPanel(JComponent component, String title) {
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.setBorder(BorderFactory.createTitledBorder(title));
    p.add(component, BorderLayout.CENTER);
    return p;//  w w w. j av a 2s .  c  om
}

From source file:SplashScreenTest.java

/**
 * This method displays a frame with the same image as the splash screen.
 *///w w w.j  a  v a 2  s .c o  m
private static void init2() {
    final Image img = Toolkit.getDefaultToolkit().getImage(splash.getImageURL());

    final JFrame splashFrame = new JFrame();
    splashFrame.setUndecorated(true);

    final JPanel splashPanel = new JPanel() {
        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, null);
        }
    };

    final JProgressBar progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    splashPanel.setLayout(new BorderLayout());
    splashPanel.add(progressBar, BorderLayout.SOUTH);

    splashFrame.add(splashPanel);
    splashFrame.setBounds(splash.getBounds());
    splashFrame.setVisible(true);

    new SwingWorker<Void, Integer>() {
        protected Void doInBackground() throws Exception {
            try {
                for (int i = 0; i <= 100; i++) {
                    publish(i);
                    Thread.sleep(100);
                }
            } catch (InterruptedException e) {
            }
            return null;
        }

        protected void process(List<Integer> chunks) {
            for (Integer chunk : chunks) {
                progressBar.setString("Loading module " + chunk);
                progressBar.setValue(chunk);
                splashPanel.repaint(); // because img is loaded asynchronously
            }
        }

        protected void done() {
            splashFrame.setVisible(false);

            JFrame frame = new JFrame();
            frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("SplashScreenTest");
            frame.setVisible(true);
        }
    }.execute();
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static JComponent createWestPanel(JComponent p) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(p, BorderLayout.WEST);
    return panel;
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static JComponent createEastPanel(JComponent p) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(p, BorderLayout.EAST);
    return panel;
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static JComponent createNorthPanel(JComponent p) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(p, BorderLayout.NORTH);
    return panel;
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static JComponent createSouthPanel(JComponent p) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(p, BorderLayout.SOUTH);
    return panel;
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static JFrame createMessageFrame(String title, String msg) {

    final JFrame frame = new JFrame(title);

    final JTextArea message = createMultiLineLabel(msg);

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;/*from ww w.  j  a  v a  2  s.  c o  m*/
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right           
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    frame.getContentPane().add(panel);
    frame.pack();
    return frame;
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static JDialog createMessageDialog(Window parent, String title, String msg) {

    final JDialog dialog = new JDialog(parent, title);

    final JTextArea message = createMultiLineLabel(msg);

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;//w w w .  ja va 2  s.  c  om
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right         
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);
    dialog.pack();
    return dialog;
}

From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

/**
 * /*from   ww w .ja  va  2  s .c o  m*/
 * @param parent
 * @param title
 * @param message
 * @return <code>true</code> if project should also be physically deleted,
 * <code>false</code> is project should be deleted but all files should be left alone,
 * <code>null</code> if user cancelled the dialog/project should not be deleted
 */
public static Boolean showDeleteProjectDialog(IAssemblyProject project) {
    final JDialog dialog = new JDialog((Window) null, "Delete project " + project.getName());

    dialog.setModal(true);

    final JTextArea message = createMultiLineLabel(
            "Do you really want to delete project '" + project.getName() + " ?");
    final JCheckBox checkbox = new JCheckBox("Delete project files");

    final DialogResult[] outcome = { DialogResult.CANCEL };

    final JButton yesButton = new JButton("Yes");
    yesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.YES;
            dialog.dispose();
        }
    });

    final JButton noButton = new JButton("No");
    noButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.NO;
            dialog.dispose();
        }
    });
    final JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            outcome[0] = DialogResult.CANCEL;
            dialog.dispose();
        }
    });

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(yesButton);
    buttonPanel.add(noButton);
    buttonPanel.add(cancelButton);

    final JPanel messagePanel = new JPanel();
    messagePanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    cnstrs.gridheight = 1;
    messagePanel.add(message, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    messagePanel.add(checkbox, cnstrs);

    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.NONE);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(5, 2, 5, 2); // top,left,bottom,right         
    panel.add(messagePanel, cnstrs);

    cnstrs = constraints(0, 1, true, true, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridheight = 1;
    cnstrs.weighty = 0;
    cnstrs.insets = new Insets(0, 2, 10, 2); // top,left,bottom,right      
    panel.add(buttonPanel, cnstrs);

    dialog.getContentPane().add(panel);
    dialog.pack();
    dialog.setVisible(true);

    if (outcome[0] != DialogResult.YES) {
        return null;
    }
    return checkbox.isSelected();
}