Example usage for java.awt GridBagLayout GridBagLayout

List of usage examples for java.awt GridBagLayout GridBagLayout

Introduction

In this page you can find the example usage for java.awt GridBagLayout GridBagLayout.

Prototype

public GridBagLayout() 

Source Link

Document

Creates a grid bag layout manager.

Usage

From source file:de.codesourcery.jasm16.ide.ui.viewcontainers.ViewFrame.java

public ViewFrame(String title, final IView component) {
    super(title);
    if (component == null) {
        throw new IllegalArgumentException("component must not be NULL.");
    }/*from   www .j av  a 2 s. c o  m*/
    this.component = component;

    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            disposeView(component);
            helper.fireViewContainerClosed(ViewFrame.this);
        }
    });

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

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

    final GridBagConstraints cnstrs = new GridBagConstraints();
    cnstrs.weightx = 1.0d;
    cnstrs.weighty = 1.0d;
    cnstrs.fill = GridBagConstraints.BOTH;
    cnstrs.gridheight = GridBagConstraints.REMAINDER;
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.gridx = 0;
    cnstrs.gridy = 0;
    panel.add(component.getPanel(this), cnstrs);
    getContentPane().add(panel);
    pack();
}

From source file:client.gui.ConnectionDialog.java

public ConnectionDialog() {

    connect = new JButton("Connect");
    connectDev = new JButton("Connect (Developer)");
    connectSame = new JButton("Connect (a as nick)");

    nick = new JTextField();
    host = new JTextField();
    port = new JTextField();

    setLayout(new GridBagLayout());

    final GridBagConstraints c = new GridBagConstraints();

    setSize(new Dimension(400, 200));

    host.setPreferredSize(new Dimension(200, 24));

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.0;//from w  w w. ja v  a2s .c om
    c.gridx = 0;
    c.gridy = 0;
    add(new JLabel("Nick:"), c);
    c.gridy = 1;
    add(new JLabel("Host:"), c);
    c.gridy = 2;
    add(new JLabel("Port:"), c);

    c.gridx = 1;

    c.gridy = 0;
    add(nick, c);

    c.gridy = 1;
    add(host, c);

    c.gridy = 2;
    add(port, c);

    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    add(connect, c);

    // c.gridy = 4;
    // add(connectDev, c);

    //  c.gridy = 5;
    //  add(connectSame, c);

    connect.addActionListener(this);
    connectDev.addActionListener(this);
    connectSame.addActionListener(this);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(final WindowEvent event) {
            dispose();
        }
    });

    final Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);

}

From source file:RenderQualityTest.java

public RenderQualityTestFrame() {
    setTitle("RenderQualityTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    buttonBox = new JPanel();
    buttonBox.setLayout(new GridBagLayout());
    hints = new RenderingHints(null);

    makeButtons("KEY_ANTIALIASING", "VALUE_ANTIALIAS_OFF", "VALUE_ANTIALIAS_ON");
    makeButtons("KEY_TEXT_ANTIALIASING", "VALUE_TEXT_ANTIALIAS_OFF", "VALUE_TEXT_ANTIALIAS_ON");
    makeButtons("KEY_FRACTIONALMETRICS", "VALUE_FRACTIONALMETRICS_OFF", "VALUE_FRACTIONALMETRICS_ON");
    makeButtons("KEY_RENDERING", "VALUE_RENDER_SPEED", "VALUE_RENDER_QUALITY");
    makeButtons("KEY_STROKE_CONTROL", "VALUE_STROKE_PURE", "VALUE_STROKE_NORMALIZE");
    canvas = new RenderQualityComponent();
    canvas.setRenderingHints(hints);/*from   w  w  w .j ava  2  s  .c  o  m*/

    add(canvas, BorderLayout.CENTER);
    add(buttonBox, BorderLayout.NORTH);
}

From source file:events.ContainerEventDemo.java

public ContainerEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    //Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    //Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//ww  w  . ja  v  a 2 s  .co  m
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; //Fill entire cell.
    c.weighty = 1.0; //Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; //Add/remove buttons have equal width.
    c.gridwidth = 1; //NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; //end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; //Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

    setPreferredSize(new Dimension(400, 400));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = c.HORIZONTAL;/* w w  w . j  a v  a2 s  . c om*/
    c.weightx = 1;
    c.weighty = 0;
    c.gridy = 0;
    final Set<String> avail = graph.getAvailableEdgeLabels();

    for (final String str : avail) {
        final JCheckBox box = new JCheckBox();
        box.setSelected(enabledLabels.contains(str));
        box.setAction(new AbstractAction(str) {
            public void actionPerformed(ActionEvent arg0) {
                if (box.isSelected() != enabledLabels.contains(str)) {
                    if (box.isSelected())
                        enabledLabels.add(str);
                    else
                        enabledLabels.remove(str);
                    v.settingsChanged(false);
                }
            }
        });
        ret.add(box, c);
        c.gridy++;
    }

    return ret;
}

From source file:cc.pinel.mangue.ui.ChaptersPanel.java

/**
 * @param main the main controller//from ww w.j  ava2s  .c o m
 * @param manga the manga
 */
public ChaptersPanel(Main main, Manga manga) {
    super(new GridBagLayout());

    this.main = main;

    chaptersPages = new KPages(PageProviders.createKBoxLayoutProvider(KBoxLayout.Y_AXIS));
    chaptersPages.setFocusable(true);
    chaptersPages.setEnabled(true);
    chaptersPages.setPageKeyPolicy(KPages.PAGE_KEYS_LOCAL);

    chapterListener = new ChapterLabelActionListener();

    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = 0;
    gc.gridy = 0;
    gc.insets = new Insets(20, 20, 20, 20);
    gc.anchor = GridBagConstraints.NORTH;
    gc.weightx = 1.0;
    gc.weighty = 1.0;
    gc.fill = GridBagConstraints.BOTH;

    add(chaptersPages, gc);

    chaptersPages.first();

    loadChapters(manga);
}

From source file:GetOpenProperties.java

public void init() {
    //Set up the layout.
    GridBagLayout gridbag = new GridBagLayout();
    setLayout(gridbag);//w ww.  ja  v  a  2s .co  m
    GridBagConstraints labelConstraints = new GridBagConstraints();
    GridBagConstraints valueConstraints = new GridBagConstraints();
    labelConstraints.anchor = GridBagConstraints.WEST;
    labelConstraints.ipadx = 10;
    valueConstraints.fill = GridBagConstraints.HORIZONTAL;
    valueConstraints.gridwidth = GridBagConstraints.REMAINDER;
    valueConstraints.weightx = 1.0; //Extra space to values column.

    //Set up the Label arrays.
    Label[] names = new Label[numProperties];
    values = new Label[numProperties];
    String firstValue = "not read yet";

    for (int i = 0; i < numProperties; i++) {
        names[i] = new Label(propertyNames[i]);
        gridbag.setConstraints(names[i], labelConstraints);
        add(names[i]);

        values[i] = new Label(firstValue);
        gridbag.setConstraints(values[i], valueConstraints);
        add(values[i]);
    }

    new Thread(this, "Loading System Properties").start();
}

From source file:flow.visibility.tapping.OpenDayLightUtils.java

/** Creating the Pane for Flow Entry */

public OpenDayLightUtils() {
    super("Installed Flow");

    FlowtextArea = new JTextArea(50, 10);
    FlowtextArea.setEditable(false);//w  w  w.j  a  v a2 s  .co  m
    FlowtextArea.setFont(new Font("Courier New", Font.BOLD, 12));
    PrintStream FlowprintStream = new PrintStream(new CustomOutputStream(FlowtextArea));

    // re-assigns standard output stream and error output stream
    System.setOut(FlowprintStream);
    System.setErr(FlowprintStream);

    // creates the GUI
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.insets = new Insets(10, 10, 10, 10);
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.gridwidth = 2;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;

    /** Adding the Pane into Frame */

    scrollPane = new JScrollPane(FlowtextArea);
    this.add(scrollPane, constraints);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setSize(400, 600);
    setLocationRelativeTo(null); // centers on screen
}

From source file:TreeExpandEventDemo2.java

public TreeExpandEventDemo2() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;/*from ww  w  . java2  s.  c o  m*/
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    demoArea = new DemoArea();
    gridbag.setConstraints(demoArea, c);
    add(demoArea);

    c.insets = new Insets(0, 0, 0, 0);
    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(200, 75));
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:de.codesourcery.eve.skills.ui.utils.PersistentDialog.java

public PersistentDialog(String id, Icon icon, String title, String label, PersistenceType type, Kind kind) {
    super(null, title, ModalityType.APPLICATION_MODAL);

    if (kind == null) {
        throw new IllegalArgumentException("kind cannot be NULL");
    }/*from  w ww  .j a  v  a 2 s .  c o  m*/

    if (StringUtils.isBlank(id)) {
        throw new IllegalArgumentException("id cannot be blank.");
    }

    if (type == null) {
        throw new IllegalArgumentException("type cannot be NULL");
    }

    if (StringUtils.isBlank(label)) {
        throw new IllegalArgumentException("label cannot be blank.");
    }

    this.id = id;
    this.type = type;

    // configure checkbox
    isDialogEnabled = new JCheckBox("Always show this dialog ?", true);
    isDialogEnabled.setHorizontalTextPosition(SwingConstants.RIGHT);

    // add panel
    final JPanel content = new JPanel();
    content.setLayout(new GridBagLayout());

    content.add(new JLabel(icon),
            new ConstraintsBuilder().x(0).y(0).anchorWest().noResizing().useRelativeWidth().end());
    content.add(new JLabel(label),
            new ConstraintsBuilder().x(1).y(0).anchorWest().resizeBoth().useRemainingWidth().end());
    content.add(isDialogEnabled, new ConstraintsBuilder().x(0).y(1).width(2).anchorWest().noResizing().end());

    final JPanel buttonPanel = new JPanel();
    buttonPanel.add(okButton);

    final ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == cancelButton) {
                wasCancelled = true;
            }
            dispose();
        }
    };

    okButton.addActionListener(listener);

    if (kind == Kind.CANCEL) {
        buttonPanel.add(cancelButton);
        cancelButton.addActionListener(listener);
    }

    content.add(buttonPanel, new ConstraintsBuilder().x(0).y(2).useRemainingSpace().end());

    getContentPane().add(content);

    pack();

    setLocationRelativeTo(null);

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            wasCancelled = true;
            dispose();
        }
    });
}