Example usage for javax.swing JPanel doLayout

List of usage examples for javax.swing JPanel doLayout

Introduction

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

Prototype

public void doLayout() 

Source Link

Document

Causes this container to lay out its components.

Usage

From source file:Main.java

/**
 * Creates a panel that contains all of the components on top of each other in north,
 * and tries to make them as small as possible (probably by using getPreferredSize()).
 *
 * @deprecated use proper layout, usually no need to use such complex/ugly layouting
 *//*from www  .  java2s  .c o  m*/
public static JPanel combineInNorth(JComponent[] components) {
    JPanel result = new JPanel();
    if (components.length == 0) {
        return result;
    }
    result.setLayout(new BorderLayout());
    JPanel contentPanel = new JPanel();
    result.add(contentPanel, BorderLayout.NORTH);
    contentPanel.setLayout(new GridBagLayout());

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.weightx = 1.0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    for (int i = 0; i < components.length; i++) {
        contentPanel.add(components[i], constraints);
    }
    if (result.isVisible())
        result.doLayout();
    return result;
}

From source file:com.wet.wired.jsr.player.JPlayer.java

public void showWindow() {

    setTitle("TestingOwl Player");
    setIconImage(owl.getWelcomeIcon().getImage());
    getContentPane().removeAll();/*from   ww  w.  j a va2s . co m*/

    JPanel panel = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    panel.setLayout(gbl);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            closePlayer();
            System.exit(0);
        }
    });

    open = new JButton("Open Recording");
    open.setActionCommand("open");
    open.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(open, gbc);

    reset = new JButton("Reset");
    reset.setActionCommand("reset");
    reset.setEnabled(false);
    reset.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(reset, gbc);

    play = new JButton("Play");
    play.setActionCommand("play");
    play.setEnabled(false);
    play.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(play, gbc);

    fastForward = new JButton("Fast Forward");
    fastForward.setActionCommand("fastForward");
    fastForward.setEnabled(false);
    fastForward.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 3;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(fastForward, gbc);

    pause = new JButton("Pause");
    pause.setActionCommand("pause");
    pause.setEnabled(false);
    pause.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 4;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(pause, gbc);

    close = new JButton("Close File");
    close.setActionCommand("close");
    close.setEnabled(false);
    close.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 5;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(close, gbc);

    // slider
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 6;
    gbc.gridy = 0;
    gbc.weightx = 1;
    gbc.weighty = 1;
    panel.add(createSliderLayout(), gbc);

    soundLevel.setSize(30, (int) close.getSize().getHeight());
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 7;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(soundLevel, gbc);

    recorder = new JButton("to Recorder");
    recorder.setActionCommand("recorder");
    recorder.setEnabled(true);
    recorder.addActionListener(this);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 8;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    panel.add(recorder, gbc);

    panel.doLayout();

    this.getContentPane().add(panel, BorderLayout.NORTH);

    panel = new JPanel();
    panel.setLayout(new GridLayout(1, 2));

    frameLabel = new JLabel("Frame: 0 Time: 0");
    frameLabel.setForeground(Color.black);
    text = new JLabel("No recording selected");
    text.setForeground(Color.black);

    panel.add(text);
    panel.add(frameLabel);

    this.getContentPane().add(panel, BorderLayout.SOUTH);

    this.setSize(700, this.getHeight());
    this.pack();
    this.setVisible(true);
}