Example usage for java.awt GridBagConstraints NORTHWEST

List of usage examples for java.awt GridBagConstraints NORTHWEST

Introduction

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

Prototype

int NORTHWEST

To view the source code for java.awt GridBagConstraints NORTHWEST.

Click Source Link

Document

Put the component at the top-left corner of its display area.

Usage

From source file:org.openconcerto.erp.core.finance.accounting.ui.EtatJournauxPanel.java

public EtatJournauxPanel() {
    super();//from w  ww  . j  ava2 s .c  o m

    this.tabbedJournaux = new JTabbedPane();

    this.setLayout(new GridBagLayout());

    final GridBagConstraints c = new DefaultGridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridwidth = 2;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 1;

    this.add(this.tabbedJournaux, c);

    JButton buttonImpression = new JButton("Impression");
    JButton buttonClose = new JButton("Fermer");
    c.gridx = 0;
    c.gridy++;
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    this.add(buttonImpression, c);
    c.gridx++;
    c.weightx = 0;
    this.add(buttonClose, c);

    buttonClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ((JFrame) SwingUtilities.getRoot(EtatJournauxPanel.this)).dispose();
        };
    });
    buttonImpression.addActionListener(new ImpressionJournauxAction());
}

From source file:org.pentaho.ui.xul.swing.tags.SwingGrid.java

@Override
public void layout() {

    if (this.getChildNodes().size() < 2) {
        logger.warn("Grid does not contain Column and Row children");
        return;/*  w  ww  .j  av  a  2s . co m*/
    }

    XulComponent columns = this.getChildNodes().get(0);
    XulComponent rows = this.getChildNodes().get(1);

    int colCount = 0;
    int rowCount = 0;
    float colFlexTotal = 0;
    float rowTotalFlex = 0;
    for (XulComponent col : columns.getChildNodes()) {
        if (col.getFlex() > 0) {
            colFlexTotal += col.getFlex();
        }
        colCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        if (row.getFlex() > 0) {
            rowTotalFlex += row.getFlex();
        }
        rowCount++;
    }

    for (XulComponent row : rows.getChildNodes()) {
        gc.gridx = 0;

        for (XulComponent xulComp : row.getChildNodes()) {
            gc.weightx = 0.0;
            gc.gridwidth = 1;
            gc.gridheight = 1;
            gc.weighty = 0.0;
            gc.anchor = GridBagConstraints.NORTHWEST;
            gc.fill = GridBagConstraints.NONE;

            Component comp = (Component) xulComp.getManagedObject();
            float colFlex = columns.getChildNodes().get(gc.gridx).getFlex();
            int rowFlex = row.getFlex();

            Align colAlignment = null;
            Align rowAlignment = null;
            String colAlignmentStr = xulComp.getAlign();
            String rowAlignStr = row.getAlign();
            if (colAlignmentStr != null) {
                colAlignment = Align.valueOf(colAlignmentStr);
            }
            if (rowAlignStr != null) {
                rowAlignment = Align.valueOf(rowAlignStr);
            }

            if (colFlex > 0) {
                gc.weightx = (colFlex / colFlexTotal);
            }
            if (rowFlex > 0) {
                gc.weighty = (rowFlex / rowTotalFlex);
            }
            if (colAlignment == Align.STRETCH && xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.BOTH;
            } else if (colAlignment == Align.STRETCH) {
                gc.fill = GridBagConstraints.HORIZONTAL;
            } else if (xulComp.getFlex() > 0) {
                gc.fill = GridBagConstraints.VERTICAL;
            }

            if (row.getChildNodes().indexOf(xulComp) + 1 == row.getChildNodes().size()) {
                gc.gridwidth = GridBagConstraints.REMAINDER;
            } else {
                gc.gridwidth = 1;
            }
            if (rows.getChildNodes().indexOf(row) + 1 == rows.getChildNodes().size()) {
                gc.gridheight = GridBagConstraints.REMAINDER;
            } else {
                gc.gridheight = 1;
            }

            // gc.gridheight = row.getFlex() + 1;

            if (colAlignment != null && rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.NORTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.NORTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.NORTHEAST;
                        break;
                    }
                    break;
                case CENTER:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.WEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.CENTER;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.EAST;
                        break;
                    }
                    break;
                case END:
                    switch (colAlignment) {
                    case START:
                        gc.anchor = GridBagConstraints.SOUTHWEST;
                        break;
                    case CENTER:
                        gc.anchor = GridBagConstraints.SOUTH;
                        break;
                    case END:
                        gc.anchor = GridBagConstraints.SOUTHEAST;
                        break;
                    }
                }
            } else if (rowAlignment != null) {
                switch (rowAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.WEST;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.SOUTHWEST;
                    break;
                }
            } else if (colAlignment != null) {

                switch (colAlignment) {
                case START:
                    gc.anchor = GridBagConstraints.NORTHWEST;
                    break;
                case CENTER:
                    gc.anchor = GridBagConstraints.NORTH;
                    break;
                case END:
                    gc.anchor = GridBagConstraints.NORTHEAST;
                    break;
                }
            }

            if (comp.getWidth() > 0 || comp.getHeight() > 0) {
                Dimension minSize = comp.getMinimumSize();
                Dimension prefSize = comp.getPreferredSize();

                if (comp.getWidth() > 0) {
                    minSize.width = comp.getWidth();
                    prefSize.width = comp.getWidth();
                }
                if (comp.getHeight() > 0) {
                    minSize.height = comp.getHeight();
                    prefSize.height = comp.getHeight();
                }
                comp.setMinimumSize(minSize);
                comp.setPreferredSize(prefSize);
            } else {
                comp.setPreferredSize(comp.getMinimumSize());
            }

            grid.add(comp, gc);
            gc.gridx++;
        }

        gc.gridy++;
    }

    if (rowTotalFlex == 0) {
        // Add in an extra row at the bottom to push others up
        gc.gridy++;
        gc.weighty = 1;
        gc.fill = gc.REMAINDER;
        grid.add(Box.createGlue(), gc);
    }
    this.initialized = true;
}

From source file:org.executequery.gui.editor.ManageShortcutsPanel.java

private void init() {

    createTextPane();/*from ww  w . j a  v  a 2 s .c  o m*/
    createList();

    JSplitPane splitPane = createSplitPane();
    splitPane.setLeftComponent(new JScrollPane(list));
    splitPane.setRightComponent(new JScrollPane(textPane));

    JPanel panel = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridy = 0;
    gbc.gridx = 1;
    gbc.insets.top = 5;
    gbc.insets.left = 5;
    gbc.insets.right = 5;
    panel.add(labelForKey("shortcuts"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 5;
    gbc.weighty = 1.0;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    panel.add(splitPane, gbc);
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.insets.left = 5;
    gbc.insets.right = 0;
    gbc.fill = GridBagConstraints.NONE;
    panel.add(createMoveButtonsPanel(), gbc);

    addActionButton(createSaveButton());
    addActionButton(createCancelButton());

    addContentPanel(panel);

    setPreferredSize(new Dimension(600, 350));
}

From source file:org.openconcerto.sql.view.listview.ListSQLView.java

protected void uiInit() {
    this.setLayout(new GridBagLayout());

    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(1, 2, 1, 2);
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = 0;/*from   ww w .jav a2  s . c om*/
    c.gridy = 0;

    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    this.add(this.itemsPanel, c);
    c.weighty = 0;
    c.gridy++;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHEAST;
    this.add(this.addBtn, c);
    this.addBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addNewItem();
        }
    });

    this.itemsConstraints.gridx = 0;
    this.itemsConstraints.gridy = 0;
    this.itemsConstraints.weightx = 1;
    this.itemsConstraints.fill = GridBagConstraints.BOTH;
}

From source file:pcgen.gui2.converter.panel.CampaignPanel.java

/**
 * @see pcgen.gui2.converter.panel.ConvertSubPanel#setupDisplay(javax.swing.JPanel, pcgen.cdom.base.CDOMObject)
 *///w w w  .j  a v  a  2  s .c  o m
@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(new GridBagLayout());
    JLabel introLabel = new JLabel("Please select the Campaign(s) to Convert:");
    GridBagConstraints gbc = new GridBagConstraints();
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
    gbc.insets = new Insets(25, 25, 5, 25);
    panel.add(introLabel, gbc);

    final CampaignTableModel model = new CampaignTableModel(gameModeCampaigns, folderName);
    final JTable table = new JTable(model) {
        //Implement table cell tool tips.
        @Override
        public String getToolTipText(MouseEvent e) {
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            String tip = String.valueOf(getValueAt(rowIndex, colIndex));
            return tip;
        }
    };
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            pc.removeListFor(ListKey.CAMPAIGN);
            int[] selRows = table.getSelectedRows();
            if (selRows.length == 0) {
                saveSourceSelection(pc);
                fireProgressEvent(ProgressEvent.NOT_ALLOWED);
            } else {
                for (int row : selRows) {
                    Campaign selCampaign = (Campaign) model.getValueAt(row, 0);
                    pc.addToListFor(ListKey.CAMPAIGN, selCampaign);
                }
                saveSourceSelection(pc);
                fireProgressEvent(ProgressEvent.ALLOWED);
            }
        }
    });

    JScrollPane listScroller = new JScrollPane(table);
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0);
    gbc.fill = GridBagConstraints.BOTH;
    panel.add(listScroller, gbc);

    initSourceSelection(model, table);
}

From source file:algorithm.OpenStegoRandomLSBSteganography.java

private void createConfigurationGui() {
    initButtons();//from  www . ja v  a2 s  .c o m
    panel = new GUIPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    panel.add(new JLabel("<html><h2>LSB embedding options</h2></html>"), constraints);
    constraints.gridy++;
    panel.add(new JLabel("Compress payload files (default true):"), constraints);
    constraints.gridx++;
    panel.add(trueCompressionButton, constraints);
    constraints.gridx++;
    panel.add(falseCompressionButton, constraints);
    constraints.gridx = 0;
    constraints.gridy++;
}

From source file:captureplugin.drivers.DeviceCreatorDialog.java

/**
 * Create the GUI/*from  w ww .ja  va 2s.c  o m*/
 */
private void createGUI() {
    UiUtilities.registerForClosing(this);

    DriverIf[] drivers = DriverFactory.getInstance().getDrivers();

    mDriverCombo = new JComboBox(drivers);
    mDriverCombo.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {

            if (value instanceof DriverIf) {
                value = ((DriverIf) value).getDriverName();
            }

            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });

    JPanel panel = (JPanel) getContentPane();

    panel.setLayout(new GridBagLayout());

    GridBagConstraints label = new GridBagConstraints();

    label.insets = new Insets(5, 5, 5, 5);
    label.anchor = GridBagConstraints.NORTHWEST;

    GridBagConstraints input = new GridBagConstraints();

    input.fill = GridBagConstraints.HORIZONTAL;
    input.weightx = 1.0;
    input.gridwidth = GridBagConstraints.REMAINDER;
    input.insets = new Insets(5, 5, 5, 5);

    panel.add(new JLabel(mLocalizer.msg("Name", "Name")), label);

    mName = new JTextField();
    panel.add(mName, input);

    panel.add(new JLabel(mLocalizer.msg("Driver", "Driver")), label);
    panel.add(mDriverCombo, input);

    mDesc = UiUtilities.createHtmlHelpTextArea("");
    mDesc.setEditable(false);

    panel.add(new JLabel(mLocalizer.msg("Description", "Description")), input);

    GridBagConstraints descC = new GridBagConstraints();
    descC.weightx = 1.0;
    descC.weighty = 1.0;
    descC.fill = GridBagConstraints.BOTH;
    descC.gridwidth = GridBagConstraints.REMAINDER;
    descC.insets = new Insets(5, 5, 5, 5);

    panel.add(new JScrollPane(mDesc, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), descC);

    final Font font = new JLabel().getFont();

    String desc = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc();
    desc = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize()
            + ";\">" + desc + "</div></html>";
    mDesc.setText(desc);
    mDesc.setFont(font);

    mDriverCombo.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            String description = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc();
            description = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:"
                    + font.getSize() + ";\">" + description + "</div></html>";
            mDesc.setText(description);
            mDesc.setFont(font);
        }

    });

    final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
    ok.setEnabled(false);
    final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
    ok.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    cancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });

    mName.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateButtons();
        }

        private void updateButtons() {
            ok.setEnabled(!mName.getText().trim().isEmpty());
        }
    });

    ButtonBarBuilder2 builder = new ButtonBarBuilder2();
    builder.addGlue();
    builder.addButton(new JButton[] { ok, cancel });

    getRootPane().setDefaultButton(ok);

    input.insets = new Insets(5, 5, 5, 5);

    panel.add(builder.getPanel(), input);

    setSize(400, 300);

}

From source file:org.zaproxy.zap.extension.encoder2.EncodeDecodeDialog.java

private void addField(JPanel parent, int index, JComponent c, String title) {
    final java.awt.GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridx = 0;/*from www  .ja  va 2s.  c  o  m*/
    gbc.gridy = index;
    gbc.insets = new java.awt.Insets(1, 1, 1, 1);
    gbc.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.weightx = 0.5D;
    gbc.weighty = 0.5D;

    final JScrollPane jsp = new JScrollPane();
    jsp.setViewportView(c);
    jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setBorder(BorderFactory.createTitledBorder(null, title, TitledBorder.DEFAULT_JUSTIFICATION,
            javax.swing.border.TitledBorder.DEFAULT_POSITION, FontUtils.getFont(FontUtils.Size.standard),
            java.awt.Color.black));

    parent.add(jsp, gbc);
}

From source file:gdt.jgui.entity.contact.JContactEditor.java

public JContactEditor() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 100, 0, 0 };
    gridBagLayout.rowHeights = new int[] { 0, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0 };
    setLayout(gridBagLayout);// w w  w.j  a v a  2 s. c o  m
    JLabel lblTitle = new JLabel("Label");

    GridBagConstraints gbc_lblTitle = new GridBagConstraints();
    gbc_lblTitle.insets = new Insets(5, 5, 5, 5);
    gbc_lblTitle.gridx = 0;
    gbc_lblTitle.gridy = 0;
    gbc_lblTitle.anchor = GridBagConstraints.NORTHWEST;
    add(lblTitle, gbc_lblTitle);
    title = new JTextField();

    GridBagConstraints gbc_title = new GridBagConstraints();
    gbc_title.insets = new Insets(5, 0, 5, 5);
    gbc_title.fill = GridBagConstraints.HORIZONTAL;
    gbc_title.gridx = 1;
    gbc_title.gridy = 0;
    add(title, gbc_title);
    title.setColumns(10);

    JLabel lblPhone = new JLabel("Phone");
    GridBagConstraints gbc_lblphone = new GridBagConstraints();
    gbc_lblphone.insets = new Insets(5, 5, 5, 5);
    gbc_lblphone.gridx = 0;
    gbc_lblphone.gridy = 1;
    gbc_lblphone.anchor = GridBagConstraints.NORTHWEST;
    add(lblPhone, gbc_lblphone);

    phone = new JTextField();
    GridBagConstraints gbc_phone = new GridBagConstraints();
    gbc_phone.insets = new Insets(5, 0, 5, 5);
    gbc_phone.fill = GridBagConstraints.HORIZONTAL;
    gbc_phone.gridx = 1;
    gbc_phone.gridy = 1;
    add(phone, gbc_phone);
    phone.setColumns(10);

    JLabel lblEmail = new JLabel("Email");
    GridBagConstraints gbc_lblEmail = new GridBagConstraints();
    gbc_lblEmail.insets = new Insets(5, 5, 5, 5);
    gbc_lblEmail.gridx = 0;
    gbc_lblEmail.gridy = 2;
    gbc_lblEmail.anchor = GridBagConstraints.NORTHWEST;
    add(lblEmail, gbc_lblEmail);

    email = new JTextField();
    GridBagConstraints gbc_email = new GridBagConstraints();
    gbc_phone.insets = new Insets(5, 0, 5, 5);
    gbc_email.fill = GridBagConstraints.HORIZONTAL;
    gbc_email.gridx = 1;
    gbc_email.gridy = 2;
    add(email, gbc_email);
    email.setColumns(10);
    JPanel panel = new JPanel();
    GridBagConstraints gbc_panel = new GridBagConstraints();
    gbc_panel.weighty = 1.0;
    gbc_panel.insets = new Insets(5, 0, 5, 5);
    gbc_panel.fill = GridBagConstraints.BOTH;
    gbc_panel.gridx = 0;
    gbc_panel.gridy = 3;
    add(panel, gbc_panel);
    panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
}

From source file:com.sec.ose.osi.ui.frm.main.identification.JPanIdentifyResetComment.java

private void initialize() {

    GridBagConstraints gridBagConstraintsPanelComment = new GridBagConstraints();
    gridBagConstraintsPanelComment.fill = GridBagConstraints.BOTH;
    gridBagConstraintsPanelComment.gridx = 0;
    gridBagConstraintsPanelComment.gridy = 0;
    gridBagConstraintsPanelComment.weightx = 1.0;
    gridBagConstraintsPanelComment.weighty = 1.0;

    GridBagConstraints gridBagConstraintsOKResetBtn = new GridBagConstraints();
    gridBagConstraintsOKResetBtn.anchor = GridBagConstraints.NORTHWEST;
    gridBagConstraintsOKResetBtn.insets = new Insets(10, 10, 0, 10);
    gridBagConstraintsOKResetBtn.gridx = 1;
    gridBagConstraintsOKResetBtn.gridy = 0;

    this.setLayout(new GridBagLayout());
    this.add(getJScrollPaneComment(), gridBagConstraintsPanelComment);
    this.add(getJPanelOkResetBtn(), gridBagConstraintsOKResetBtn);
}