Example usage for java.awt GridBagLayout addLayoutComponent

List of usage examples for java.awt GridBagLayout addLayoutComponent

Introduction

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

Prototype

public void addLayoutComponent(Component comp, Object constraints) 

Source Link

Document

Adds the specified component to the layout, using the specified constraints object.

Usage

From source file:net.chaosserver.timelord.swingui.SummaryPanel.java

/**
 * Constructs the panel./*w w  w  .ja v  a 2s.co  m*/
 */
protected void buildSummaryPanel() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    setLayout(gridBagLayout);

    if (isToday()) {
        JLabel remainderName = new JLabel("Remainder");
        gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
        gridBagConstraints.weightx = LayoutConstants.HEAVY_WEIGHT;
        gridBagConstraints.insets = new Insets(0, LayoutConstants.SMALL_INSET, 0, LayoutConstants.BIG_INSET);
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        gridBagConstraints.gridwidth = 1;
        gridBagLayout.addLayoutComponent(remainderName, gridBagConstraints);
        add(remainderName);

        timeLeftLabel = new JLabel();
        gridBagConstraints.anchor = GridBagConstraints.SOUTHEAST;
        gridBagConstraints.fill = GridBagConstraints.NONE;
        gridBagConstraints.weightx = 0;
        gridBagConstraints.insets = new Insets(0, LayoutConstants.BIG_INSET, 0, LayoutConstants.SMALL_INSET);
        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagLayout.addLayoutComponent(timeLeftLabel, gridBagConstraints);
        add(timeLeftLabel);
    }

    JLabel taskName = new JLabel("Total");
    gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = LayoutConstants.HEAVY_WEIGHT;
    gridBagConstraints.insets = new Insets(0, LayoutConstants.SMALL_INSET, 0, LayoutConstants.BIG_INSET);
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.gridwidth = 1;
    gridBagLayout.addLayoutComponent(taskName, gridBagConstraints);
    add(taskName);

    totalTimeLabel = new JLabel();
    gridBagConstraints.anchor = GridBagConstraints.NORTHEAST;
    gridBagConstraints.fill = GridBagConstraints.NONE;
    gridBagConstraints.weightx = 0;
    gridBagConstraints.insets = new Insets(0, LayoutConstants.BIG_INSET, 0, LayoutConstants.SMALL_INSET);
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.addLayoutComponent(totalTimeLabel, gridBagConstraints);
    add(totalTimeLabel);

    updateTotalTimeLabel();
    updateTimeLeftLabel();
}

From source file:net.chaosserver.timelord.swingui.TaskDayPanel.java

/**
 * Builds the panel. This uses a GridBag to try and make formatting
 * grid-like between the unconnected rows.
 *///from www  .j ava 2  s .co  m
protected void buildPanel() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    Insets defaultInsets = gridBagConstraints.insets;

    setLayout(gridBagLayout);

    taskName = new JLabel();

    if (timelordTask.isHidden()) {
        Font taskFont = taskName.getFont();
        Font italicFont = new Font(taskFont.getName(), Font.ITALIC, taskFont.getSize());
        taskName.setFont(italicFont);
    }

    updateTaskNameLabel();
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.weightx = LayoutConstants.HEAVY_WEIGHT;
    gridBagConstraints.insets = new Insets(0, LayoutConstants.SMALL_INSET, 0, LayoutConstants.BIG_INSET);
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagLayout.addLayoutComponent(taskName, gridBagConstraints);
    add(taskName);

    minusButton = new JButton("-" + DateUtil.getSmallestTimeInMinutes() + "m");

    minusButton.setToolTipText("Remove 15 minutes (0.25 hours) " + "of time from this task.");
    minusButton.setActionCommand(ACTION_MINUS_15);
    minusButton.addActionListener(this);
    gridBagConstraints.anchor = GridBagConstraints.CENTER;
    gridBagConstraints.insets = defaultInsets;
    gridBagConstraints.fill = GridBagConstraints.NONE;
    gridBagConstraints.weightx = 0;
    gridBagLayout.addLayoutComponent(minusButton, gridBagConstraints);
    add(minusButton);

    addButton = new JButton("+" + DateUtil.getSmallestTimeInMinutes() + "m");

    addButton.setToolTipText("Add 15 minutes (0.25 hours) of " + "time from this task.");
    addButton.setActionCommand(ACTION_ADD_15);
    addButton.addActionListener(this);
    gridBagConstraints.anchor = GridBagConstraints.CENTER;
    gridBagConstraints.insets = defaultInsets;
    gridBagConstraints.fill = GridBagConstraints.NONE;
    gridBagConstraints.weightx = 0;
    gridBagLayout.addLayoutComponent(addButton, gridBagConstraints);
    add(addButton);

    timeLabel = new JLabel();

    if (todayTaskDay != null) {
        timeLabel.setText(DateUtil.formatHours(null, todayTaskDay.getHours()));
    } else {
        timeLabel.setText(DateUtil.formatHours(null, 0));
    }

    gridBagConstraints.anchor = GridBagConstraints.EAST;
    gridBagConstraints.fill = GridBagConstraints.NONE;
    gridBagConstraints.weightx = 0;
    gridBagConstraints.insets = new Insets(0, LayoutConstants.BIG_INSET, 0, LayoutConstants.SMALL_INSET);
    gridBagLayout.addLayoutComponent(timeLabel, gridBagConstraints);
    add(timeLabel);

    enabledButtons();
}