Example usage for java.awt GridBagConstraints BOTH

List of usage examples for java.awt GridBagConstraints BOTH

Introduction

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

Prototype

int BOTH

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

Click Source Link

Document

Resize the component both horizontally and vertically.

Usage

From source file:com.jostrobin.battleships.view.panels.PlacementPanel.java

@Override
public void afterPropertiesSet() throws Exception {
    setLayout(new GridBagLayout());

    battleField = new BattleFieldPanel("");
    GridBagConstraints gamePanelConstraints = new GridBagConstraints();
    gamePanelConstraints.weightx = 0.6;//from   w w w .  j a  va 2  s.  c om
    gamePanelConstraints.weighty = 1.0;
    gamePanelConstraints.gridy = y;
    gamePanelConstraints.gridheight = 4;
    gamePanelConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    gamePanelConstraints.fill = GridBagConstraints.BOTH;
    add(battleField, gamePanelConstraints);

    rotate = new JButton("Rotate ship");
    rotate.addActionListener(this);
    GridBagConstraints leftButtonConstraints = new GridBagConstraints();
    leftButtonConstraints.gridy = y++;
    leftButtonConstraints.gridx = 1;
    leftButtonConstraints.fill = GridBagConstraints.NONE;
    leftButtonConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    add(rotate, leftButtonConstraints);

    random = new JButton("Random");
    random.addActionListener(this);
    GridBagConstraints randomButtonConstraints = new GridBagConstraints();
    randomButtonConstraints.gridy = y++;
    randomButtonConstraints.gridx = 1;
    randomButtonConstraints.fill = GridBagConstraints.NONE;
    randomButtonConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    random.addActionListener(this);
    add(random, randomButtonConstraints);

    shipsPanel = new ShipsPanel();
    GridBagConstraints shipsPanelConstraints = new GridBagConstraints();
    shipsPanelConstraints.weightx = 1.0;
    shipsPanelConstraints.weighty = 1.0;
    shipsPanelConstraints.anchor = GridBagConstraints.BASELINE;
    shipsPanelConstraints.fill = GridBagConstraints.BOTH;
    shipsPanelConstraints.gridy = y++;
    shipsPanelConstraints.gridx = 1;
    add(shipsPanel, shipsPanelConstraints);

    ready = new JButton("I'm ready");
    ready.addActionListener(this);
    GridBagConstraints readyButtonConstraints = new GridBagConstraints();
    readyButtonConstraints.gridy = y++;
    readyButtonConstraints.gridx = 1;
    readyButtonConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    ready.setEnabled(false);
    add(ready, readyButtonConstraints);

    updateShips();
}

From source file:com.igormaznitsa.sciareto.ui.tabs.TabTitle.java

public TabTitle(@Nonnull final Context context, @Nonnull final TabProvider parent,
        @Nullable final File associatedFile) {
    super(new GridBagLayout());
    this.parent = parent;
    this.context = context;
    this.associatedFile = associatedFile;
    this.changed = this.associatedFile == null;
    this.setOpaque(false);
    final GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weightx = 1000.0d;/* w w w .j a v a2 s .co  m*/

    final TabTitle theInstance = this;

    this.titleLabel = new JLabel() {
        private static final long serialVersionUID = 8689945842487138781L;

        @Override
        protected void processKeyEvent(@Nonnull final KeyEvent e) {
            theInstance.getParent().dispatchEvent(e);
        }

        @Override
        public String getToolTipText() {
            return theInstance.getToolTipText();
        }

        @Override
        public boolean isFocusable() {
            return false;
        }
    };
    this.add(this.titleLabel, constraints);

    final Icon uiCloseIcon = UIManager.getIcon("InternalFrameTitlePane.closeIcon");

    this.closeButton = new JButton(uiCloseIcon == null ? NIMBUS_CLOSE_ICON : uiCloseIcon) {
        private static final long serialVersionUID = -8005282815756047979L;

        @Override
        public String getToolTipText() {
            return theInstance.getToolTipText();
        }

        @Override
        public boolean isFocusable() {
            return false;
        }
    };
    this.closeButton.setToolTipText("Close tab");
    this.closeButton.setBorder(null);
    this.closeButton.setContentAreaFilled(false);
    this.closeButton.setMargin(new Insets(0, 0, 0, 0));
    this.closeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    this.closeButton.setOpaque(false);
    this.closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(@Nonnull final ActionEvent e) {
            doSafeClose();
        }
    });
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weightx = 0.0d;
    constraints.insets = new Insets(2, 8, 2, 0);

    this.add(this.closeButton, constraints);

    updateView();

    ToolTipManager.sharedInstance().registerComponent(closeButton);
    ToolTipManager.sharedInstance().registerComponent(this.titleLabel);
    ToolTipManager.sharedInstance().registerComponent(this);
}

From source file:MouseEventDemo.java

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

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;//from w  w  w.  j  a v  a 2s . c  o m
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f));
    gridbag.setConstraints(blankArea, c);
    add(blankArea);

    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);

    //Register for mouse events on blankArea and the panel.
    blankArea.addMouseListener(this);
    addMouseListener(this);

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

From source file:SwingMouseMotionEventDemo.java

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

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;/*from w w w.  j  a v a2  s . c om*/
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f));
    gridbag.setConstraints(blankArea, c);
    add(blankArea);

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

    //Register for mouse events on blankArea and panel.
    blankArea.addMouseMotionListener(this);
    addMouseMotionListener(this);

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

From source file:MultiListener.java

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

    JLabel l = null;// w w  w. ja  v a 2 s  . com

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    l = new JLabel("What MultiListener hears:");
    gridbag.setConstraints(l, c);
    add(l);

    c.weighty = 1.0;
    topTextArea = new JTextArea();
    topTextArea.setEditable(false);
    JScrollPane topScrollPane = new JScrollPane(topTextArea);
    Dimension preferredSize = new Dimension(200, 75);
    topScrollPane.setPreferredSize(preferredSize);
    gridbag.setConstraints(topScrollPane, c);
    add(topScrollPane);

    c.weightx = 0.0;
    c.weighty = 0.0;
    l = new JLabel("What Eavesdropper hears:");
    gridbag.setConstraints(l, c);
    add(l);

    c.weighty = 1.0;
    bottomTextArea = new JTextArea();
    bottomTextArea.setEditable(false);
    JScrollPane bottomScrollPane = new JScrollPane(bottomTextArea);
    bottomScrollPane.setPreferredSize(preferredSize);
    gridbag.setConstraints(bottomScrollPane, c);
    add(bottomScrollPane);

    c.weightx = 1.0;
    c.weighty = 0.0;
    c.gridwidth = 1;
    c.insets = new Insets(10, 10, 0, 10);
    button1 = new JButton("Blah blah blah");
    gridbag.setConstraints(button1, c);
    add(button1);

    c.gridwidth = GridBagConstraints.REMAINDER;
    button2 = new JButton("You don't say!");
    gridbag.setConstraints(button2, c);
    add(button2);

    button1.addActionListener(this);
    button2.addActionListener(this);

    button2.addActionListener(new Eavesdropper(bottomTextArea));

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
}

From source file:com.stefanbrenner.droplet.ui.ActionPanel.java

/**
 * Create the panel.//  w  w  w.  j av  a  2  s  .  co  m
 */
public ActionPanel(final IActionDevice device, final T action) {

    setDevice(device);
    setAction(action);

    setLayout(new GridBagLayout());
    setBackground(DropletColors.getBackgroundColor(getDevice()));

    GridBagConstraints gbc = UiUtils.createGridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new Insets(2, 2, 2, 2);

    BeanAdapter<IAction> adapter = new BeanAdapter<IAction>(action, true);

    // enabled checkbox
    cbEnable = BasicComponentFactory.createCheckBox(adapter.getValueModel(IAction.PROPERTY_ENABLED),
            StringUtils.EMPTY);
    cbEnable.setToolTipText(Messages.getString("ActionPanel.enableAction.tooltip")); //$NON-NLS-1$
    cbEnable.setFocusable(false);
    UiUtils.editGridBagConstraints(gbc, 0, 0, 0, 0);
    add(cbEnable, gbc);

    // offset spinner
    spOffset = new MouseWheelSpinner(true);
    spOffset.setToolTipText(Messages.getString("ActionPanel.Offset.Tooltip")); //$NON-NLS-1$
    spOffset.setModel(SpinnerAdapterFactory.createNumberAdapter(adapter.getValueModel(IAction.PROPERTY_OFFSET),
            0, 0, ActionPanel.MAX_TIME_INPUT, 1));
    ((JSpinner.DefaultEditor) spOffset.getEditor()).getTextField().setColumns(4);
    UiUtils.editGridBagConstraints(gbc, 1, 0, 0, 0);
    add(spOffset, gbc);

    // duration spinner
    spDuration = new MouseWheelSpinner(true);
    spDuration.setToolTipText(Messages.getString("ActionPanel.Duration.Tooltip")); //$NON-NLS-1$
    if (action instanceof IDurationAction) {
        spDuration.setModel(SpinnerAdapterFactory.createNumberAdapter(
                adapter.getValueModel(IDurationAction.PROPERTY_DURATION), 0, 0, ActionPanel.MAX_TIME_INPUT, 1));
        ((JSpinner.DefaultEditor) spDuration.getEditor()).getTextField().setColumns(4);
        UiUtils.editGridBagConstraints(gbc, 2, 0, 0, 0);
        add(spDuration, gbc);
    }

    // remove button
    btnRemove = new JButton(Messages.getString("ActionPanel.removeAction")); //$NON-NLS-1$
    btnRemove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            remove();
        }
    });
    btnRemove.setToolTipText(Messages.getString("ActionPanel.removeAction.tooltip")); //$NON-NLS-1$
    btnRemove.setFocusable(false);
    UiUtils.editGridBagConstraints(gbc, 3, 0, 0, 0);
    add(btnRemove, gbc);

}

From source file:Demo.HistGraph.java

public HistGraph(List<String> paraType_list) {
    this.paraType_list = paraType_list;

    // widgets: charts(JFreeChart), parameter selector (JList)
    chartPane = new ChartPanel(null);
    charts = new JFreeChart[paraType_list.size()];

    DefaultListModel modelOfList = new DefaultListModel();
    paraSelector = new JList(modelOfList);

    for (int i = 0; i < paraType_list.size(); i++) {
        modelOfList.addElement(paraType_list.get(i));
        charts[i] = null;/*from  w  w  w.  jav a2 s. c o m*/
    }

    paraSelector.setSelectedIndex(0);

    charts[0] = CreateChart(paraType_list.get(0));
    chartPane.setChart(charts[0]);

    JScrollPane selectorPanel = new JScrollPane();
    selectorPanel.setViewportView(paraSelector);

    paraSelector.addMouseListener(this);

    // layout
    GridBagLayout layout = new GridBagLayout();
    setLayout(layout);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;

    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;

    gbc.insets = new Insets(5, 20, 5, 5);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 20;
    add(new JLabel("Distribution:"), gbc);

    gbc.insets = new Insets(5, 5, 5, 20);
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 1;
    add(new JLabel("Parameters:"), gbc);

    gbc.weighty = 14;

    gbc.insets = new Insets(5, 20, 5, 5);
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.weightx = 20;
    add(chartPane, gbc);

    gbc.insets = new Insets(5, 5, 15, 20);
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.weightx = 1;
    add(selectorPanel, gbc);
}

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

public AjouterComptePCGtoPCEFrame() {

    super("Ajouter un compte du plan comptable gnral");
    Container f = this.getContentPane();

    // instanciation du panel et du menu click droit associ
    Vector<AbstractAction> actionClickDroitTable = new Vector<AbstractAction>();

    actionClickDroitTable.add(new AbstractAction("Ajouter au PCE") {

        public void actionPerformed(ActionEvent e) {
            ajoutCompteSelected();//  w w w  .j  a  va2s  .c o m
        }
    });

    this.planPanel = new PlanComptableGPanel(actionClickDroitTable);

    this.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(12, 2, 12, 2);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridwidth = 2;
    c.gridheight = 1;
    JLabel label = new JLabel("Choississez le ou les comptes  ajouter au Plan Comptable Entreprise");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    f.add(label, c);

    /*******************************************************************************************
     * * Affichage du plan comptable entreprise
     ******************************************************************************************/
    c.insets = new Insets(0, 0, 0, 0);
    c.gridwidth = 2;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.gridy++;
    f.add(this.planPanel, c);

    /*******************************************************************************************
     * * Bouton ajout / fermer
     ******************************************************************************************/
    c.insets = new Insets(2, 2, 1, 2);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    c.gridy++;
    c.gridx = 0;
    c.anchor = GridBagConstraints.SOUTHEAST;

    f.add(this.boutonAjout, c);

    this.boutonAjout.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            ajoutCompteSelected();

        }
    });

    c.gridx++;
    f.add(this.boutonClose, c);
    this.boutonClose.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            AjouterComptePCGtoPCEFrame.this.setVisible(false);
            AjouterComptePCGtoPCEFrame.this.dispose();
        }
    });
    /*
     * this.pack(); this.setVisible(true);
     */
}

From source file:com.digitalgeneralists.assurance.ui.components.ScanHistoryPanel.java

private void initializeComponent() {
    if (!this.initialized) {
        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        GridBagConstraints existingScansPanelConstraints = new GridBagConstraints();
        existingScansPanelConstraints.anchor = GridBagConstraints.WEST;
        existingScansPanelConstraints.fill = GridBagConstraints.BOTH;
        existingScansPanelConstraints.gridx = 0;
        existingScansPanelConstraints.gridy = 0;
        existingScansPanelConstraints.weightx = 1.0;
        existingScansPanelConstraints.weighty = 1.0;
        existingScansPanelConstraints.gridheight = 1;
        existingScansPanelConstraints.gridwidth = 1;
        existingScansPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.existingScansListPanel = new ListInputPanel<Scan>(this, this, true, true);
        this.add(this.existingScansListPanel, existingScansPanelConstraints);

        this.addAncestorListener(new AncestorListener() {
            public void ancestorAdded(AncestorEvent event) {
                applicationDelegate.addEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScansLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanDeletedEvent.class,
                        (IEventObserver) event.getSource());

                applicationDelegate.loadScans();
            }/*from   w  w w. j a v a 2 s.  com*/

            public void ancestorRemoved(AncestorEvent event) {
                applicationDelegate.removeEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScansLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanDeletedEvent.class,
                        (IEventObserver) event.getSource());
            }

            public void ancestorMoved(AncestorEvent event) {
            }
        });

        this.initialized = true;
    }
}

From source file:MultipartViewer.java

protected void setupDisplay(Multipart mp) {
    // we display the first body part in a main frame on the left, and then
    // on the right we display the rest of the parts as attachments

    GridBagConstraints gc = new GridBagConstraints();
    gc.gridheight = GridBagConstraints.REMAINDER;
    gc.fill = GridBagConstraints.BOTH;
    gc.weightx = 1.0;/*  ww w  . j  av a 2  s . com*/
    gc.weighty = 1.0;

    // get the first part
    try {
        BodyPart bp = mp.getBodyPart(0);
        Component comp = getComponent(bp);
        add(comp, gc);

    } catch (MessagingException me) {
        add(new Label(me.toString()), gc);
    }

    // see if there are more than one parts
    try {
        int count = mp.getCount();

        // setup how to display them
        gc.gridwidth = GridBagConstraints.REMAINDER;
        gc.gridheight = 1;
        gc.fill = GridBagConstraints.NONE;
        gc.anchor = GridBagConstraints.NORTH;
        gc.weightx = 0.0;
        gc.weighty = 0.0;
        gc.insets = new Insets(4, 4, 4, 4);

        // for each one we create a button with the content type
        for (int i = 1; i < count; i++) { // we skip the first one 
            BodyPart curr = mp.getBodyPart(i);
            String label = null;
            if (label == null)
                label = curr.getFileName();
            if (label == null)
                label = curr.getDescription();
            if (label == null)
                label = curr.getContentType();

            Button but = new Button(label);
            but.addActionListener(new AttachmentViewer(curr));
            add(but, gc);
        }

    } catch (MessagingException me2) {
        me2.printStackTrace();
    }

}