Example usage for javax.swing Box setBackground

List of usage examples for javax.swing Box setBackground

Introduction

In this page you can find the example usage for javax.swing Box setBackground.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:com.diversityarrays.kdxplore.field.FieldViewPanel.java

public FieldViewPanel(PlotVisitList plotVisitList, Map<Integer, Trait> traitMap,
        SeparatorVisibilityOption visible, SimplePlotCellRenderer plotRenderer, Component... extras) {
    super(new BorderLayout());

    this.plotVisitList = plotVisitList;
    this.traitMap = traitMap;

    trial = plotVisitList.getTrial();//  w w  w . ja v a2 s .com

    fieldLayoutTableModel.setTrial(trial);

    int rowHeight = fieldLayoutTable.getRowHeight();
    fieldLayoutTable.setRowHeight(4 * rowHeight);

    fieldLayoutTable.setCellSelectionEnabled(true);

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    // IMPORTANT: DO NOT SORT THE FIELD LAYOUT TABLE
    fieldLayoutTable.setAutoCreateRowSorter(false);

    Map<Integer, Plot> plotById = new HashMap<>();
    FieldLayout<Integer> plotIdLayout = FieldLayoutUtil.createPlotIdLayout(trial.getTrialLayout(),
            trial.getPlotIdentSummary(), plotVisitList.getPlots(), plotById);

    KdxploreFieldLayout<Plot> kdxFieldLayout = new KdxploreFieldLayout<Plot>(Plot.class, plotIdLayout.imageId,
            plotIdLayout.xsize, plotIdLayout.ysize);
    kdxFieldLayout.warning = plotIdLayout.warning;

    String displayName = null;
    for (VisitOrder2D vo : VisitOrder2D.values()) {
        if (vo.imageId == plotIdLayout.imageId) {
            displayName = vo.displayName;
            break;
        }
    }
    //      VisitOrder2D vo = plotVisitList.getVisitOrder();
    KDClientUtils.initAction(plotIdLayout.imageId, changeCollectionOrder, displayName);

    hasUserPlotId = lookForUserPlotIdPresent(plotById, plotIdLayout, kdxFieldLayout);

    this.plotCellRenderer = plotRenderer;
    plotCellRenderer.setShowUserPlotId(hasUserPlotId);

    plotCellRenderer.setPlotXYprovider(getXYprovider());

    plotCellRenderer.setPlotVisitList(plotVisitList);

    fieldLayoutTable.setDefaultRenderer(Plot.class, plotCellRenderer);
    fieldLayoutTable.setCellSelectionEnabled(true);

    fieldLayoutTableModel.setFieldLayout(kdxFieldLayout);

    if (kdxFieldLayout.warning != null && !kdxFieldLayout.warning.isEmpty()) {
        warningMessage.setText(kdxFieldLayout.warning);
    } else {
        warningMessage.setText("");
    }

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    fieldLayoutTable.getTableHeader().setReorderingAllowed(false);
    fieldLayoutTable.setCellSelectionEnabled(true);

    StringBuilder naming = new StringBuilder();
    String nameForRow = plotVisitList.getTrial().getNameForRow();
    if (!Check.isEmpty(nameForRow)) {
        naming.append(nameForRow);
    }
    String nameForCol = plotVisitList.getTrial().getNameForColumn();
    if (!Check.isEmpty(nameForCol)) {
        if (naming.length() > 0) {
            naming.append('/');
        }
        naming.append(nameForCol);
    }
    fieldTableScrollPane = new JScrollPane(fieldLayoutTable);
    if (naming.length() > 0) {
        JLabel cornerLabel = new JLabel(naming.toString());
        fieldTableScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, cornerLabel);
    }
    fieldTableScrollPane.setRowHeaderView(rowHeaderTable);

    //      fieldLayoutTable.setRowHeaderTable(rowHeaderTable);

    //      Box extra = Box.createHorizontalBox();
    //      extra.add(new JButton(changeCollectionOrder));
    //      if (extras != null && extras.length > 0) {
    //         extra.add(Box.createHorizontalStrut(8));
    //         for (Component c : extras) {
    //            extra.add(c);
    //         }
    //      }
    //      extra.add(Box.createHorizontalGlue());

    switch (visible) {
    case NOTVISIBLE:
        break;

    case VISIBLE:
    default:
        Box top = Box.createHorizontalBox();
        top.setOpaque(true);
        top.setBackground(Color.LIGHT_GRAY);
        top.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));
        JLabel label = new JLabel("Field");
        label.setForeground(Color.DARK_GRAY);
        label.setFont(label.getFont().deriveFont(Font.BOLD));
        top.add(label);
        top.add(new JButton(changeCollectionOrder));

        if (extras != null && extras.length > 0) {
            top.add(Box.createHorizontalStrut(8));
            for (Component c : extras) {
                top.add(c);
            }
        }
        add(top, BorderLayout.NORTH);
        break;
    }

    add(fieldTableScrollPane, BorderLayout.CENTER);
    add(warningMessage, BorderLayout.SOUTH);
}