Example usage for javax.swing JPanel setBackground

List of usage examples for javax.swing JPanel setBackground

Introduction

In this page you can find the example usage for javax.swing JPanel 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:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    JPanel upper = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    upper.setLayout(gridbag);//from  ww  w .  ja  v a  2s.  com
    GridBagConstraints gbc = new GridBagConstraints();

    JButton toolbar1 = new JButton("toolbar1");
    JButton toolbar2 = new JButton("toolbar2");
    JButton toolbar3 = new JButton("toolbar3");

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.WEST;
    upper.add(toolbar1, gbc);

    gbc.gridx = 1;
    gbc.anchor = GridBagConstraints.CENTER;
    upper.add(toolbar2, gbc);

    gbc.gridx = 2;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    upper.add(toolbar3, gbc);

    add(upper, BorderLayout.NORTH);

    JPanel something = new JPanel();
    something.setBackground(Color.WHITE);
    something.setPreferredSize(new Dimension(600, 600));
    something.repaint();
    add(something, BorderLayout.CENTER);

    pack();
    setVisible(true);
}

From source file:MainClass.java

public JPanel createNested(boolean opaque) {
    JPanel outer = new JPanel(new FlowLayout());
    JPanel inner = new JPanel(new FlowLayout());
    outer.setBackground(Color.white);
    inner.setBackground(Color.black);

    inner.setOpaque(opaque);/*w ww .j  a  va2s  .c om*/
    inner.setBorder(BorderFactory.createLineBorder(Color.gray));

    inner.add(new JButton("Button"));
    outer.add(inner);

    return outer;
}

From source file:SplashScreen.java

public void showSplash() {
    JPanel content = (JPanel) getContentPane();
    content.setBackground(Color.white);

    // Set the window's bounds, centering the window
    int width = 450;
    int height = 115;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);//w w w .  j  a  v a  2 s  . c  o  m

    // Build the splash screen
    JLabel label = new JLabel(new ImageIcon("1.gif"));
    JLabel copyrt = new JLabel("Copyright 2002, O'Reilly & Associates", JLabel.CENTER);
    copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    content.add(label, BorderLayout.CENTER);
    content.add(copyrt, BorderLayout.SOUTH);
    Color oraRed = new Color(156, 20, 20, 255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 10));

    // Display it
    setVisible(true);

    // Wait a little while, maybe while loading resources
    try {
        Thread.sleep(duration);
    } catch (Exception e) {
    }

    setVisible(false);
}

From source file:ComplexExample.java

public ComplexExample() {
    JPanel left = new JPanel();
    left.setBackground(Color.red);

    JPanel right = new JPanel();
    right.setBackground(Color.white);

    new MyDropTargetListener(right);

    DragSource ds = new DragSource();
    ds.createDefaultDragGestureRecognizer(left, DnDConstants.ACTION_COPY, this);

    setLayout(new FlowLayout());
    add(left);//ww  w  .  j  a  v a  2 s .  c  o m
    add(right);

    setSize(40, 50);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    setVisible(true);
}

From source file:probe.com.model.util.vaadintoimageutil.HeatmapSwingComponent.java

private JPanel initCell(String color, int x, int y) {
    JPanel cell = new JPanel();
    cell.setSize(50, 50);/*  w w  w . ja v a  2  s. co m*/
    cell.setBackground(Color.decode(color));
    cell.setOpaque(true);
    cell.setLocation(x, y);
    cell.setBorder(new LineBorder(Color.WHITE));
    return cell;

}

From source file:net.ontopia.topicmaps.viz.AboutFrame.java

public AboutFrame(Frame parent) {
    super(parent, Messages.getString("Viz.About", "Ontopia Vizigator"), true);

    JPanel mainPanel = new JPanel();
    mainPanel.setBackground(Color.white);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.add(createImagePanel());//from  ww  w  . ja v a 2s  .c om
    mainPanel.add(createAboutTextPanel());

    this.getContentPane().add(mainPanel);
    this.pack();
    this.setResizable(false);
    //    Center the dialog box above its parent
    this.setLocation((parent.getX() + (parent.getWidth() - this.getWidth()) / 2),
            parent.getY() + (parent.getHeight() - this.getHeight()) / 2);
}

From source file:MonthPanel.java

protected JPanel createTitleGUI() {
    JPanel titlePanel = new JPanel(true);
    titlePanel.setLayout(new FlowLayout());
    titlePanel.setBackground(Color.WHITE);

    JLabel label = new JLabel(monthNames[month] + " " + year);
    label.setForeground(SystemColor.activeCaption);
    titlePanel.add(label, BorderLayout.CENTER);
    return titlePanel;
}

From source file:CardLayoutBehaviour.java

public CardLayoutBehaviour() {
    JPanel tab;
    Container pane = getContentPane();
    layout = new CardLayout();
    pane.setLayout(layout);/*from  w  w  w.j  av  a 2s  .  com*/
    tab = new JPanel();
    tab.setBackground(Color.red);
    pane.add(tab, "Red Tab");
    tab = new JPanel();
    tab.setBackground(Color.green);
    pane.add(tab, "Green Tab");
    tab = new JPanel();
    tab.setBackground(Color.blue);
    pane.add(tab, "Blue Tab");
}

From source file:soap.ui.panel.innerCentralPanel.StatsPanel.java

protected void initUI() {
    if (mIndicatorsName.size() != 0) {
        defaultAddComponent(new JLabel(resMan.getString("statsChooseIndicator")), SoapGridbagPanel.END);

        JPanel indicatorsPanel = new JPanel();
        indicatorsPanel.setBackground(Color.WHITE);
        indicatorsPanel.setLayout(new GridLayout(mIndicatorsName.size(), 1));
        mCheckBoxTable = new JCheckBox[mIndicatorsName.size()];
        CheckBoxListener listener = new CheckBoxListener();
        Iterator it = mIndicatorsName.keySet().iterator();
        for (int i = 0; i < mIndicatorsName.size(); i++) {
            String key = (String) it.next();
            mCheckBoxTable[i] = new JCheckBox((String) mIndicatorsName.get(key));
            mCheckBoxTable[i].setName(key);
            mCheckBoxTable[i].setPreferredSize(new Dimension(50, 20));
            mCheckBoxTable[i].setBackground(Color.WHITE);
            mCheckBoxTable[i].addItemListener(listener);
            indicatorsPanel.add(mCheckBoxTable[i]);
        }//w  w w  . j  ava 2  s.  c  o  m
        JScrollPane scrollPane = new JScrollPane(indicatorsPanel);
        scrollPane.setPreferredSize(new Dimension(140, 65));
        defaultAddComponent(scrollPane, SoapGridbagPanel.END, 1, 0, new Insets(10, 0, 20, 0));

        // add the chart to a panel...
        mChartPanel.setPreferredSize(new Dimension(580, 330));
        defaultAddComponent(new JScrollPane(mChartPanel), SoapGridbagPanel.END);
    }
}

From source file:customprogressindicator.CustomProgress.java

private JPanel createComponents() {
    JPanel top = new JPanel();
    top.setBackground(Color.WHITE);
    top.setLayout(new BorderLayout(20, 20));

    // get applet parameter using an instance of the AppletStub class
    // "tagLine" parameter specified in applet's JNLP file
    String tagLine = "";
    if (appletStub != null) {
        tagLine = appletStub.getParameter("tagLine");
    }/*from   w w  w .ja va 2  s . c o  m*/
    String lblText = "<html><font color=red size=+2>JDK Documentation</font><br/>" + tagLine + " <br/></html>";
    JLabel lbl = new JLabel(lblText);
    top.add(lbl, BorderLayout.NORTH);

    // use JSObject.getWindow(null) method to retrieve a reference to
    // the web page and make JavaScript calls. Duke logo displayed if
    // displayLogo variable set to "true" in the web page
    String displayLogo = "false";
    JSObject window = JSObject.getWindow(null);
    if (window != null) {
        displayLogo = (String) window.getMember("displayLogo");
    }
    if (displayLogo.equals("true")) {
        lbl = new JLabel();
        ImageIcon logo = createImageIcon("images/DukeWave.gif", "logo");
        lbl.setIcon(logo);
        top.add(lbl, BorderLayout.EAST);
    }

    statusLabel = new JLabel("<html><font color=green size=-2>Loading applet...</font></html>");
    top.add(statusLabel, BorderLayout.CENTER);

    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    top.add(progressBar, BorderLayout.SOUTH);

    return top;
}