Example usage for java.awt Container setBackground

List of usage examples for java.awt Container setBackground

Introduction

In this page you can find the example usage for java.awt Container setBackground.

Prototype

public void setBackground(Color c) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:room.utilization.BarGraph.java

private void createBarGraph() {
    Container contentPane = getContentPane();

    contentPane.setBackground(Color.WHITE);

    setSize(700, 500);/*from   w ww.  jav  a 2s .c  om*/
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setLocation(500, 250);
    setIconImage(new ImageIcon(
            "C:\\Users\\Olasubomi\\Documents\\NetBeansProjects\\Room Utilization\\src\\room\\utilization\\icon.png")
                    .getImage());
    contentPane.add(createPanel());
    setVisible(true);
}

From source file:ColorPicker.java

public ColorPicker() {
    super("JColorChooser Test Frame");
    setSize(200, 100);/*from ww  w .  j a  va  2 s  . c o  m*/
    final Container contentPane = getContentPane();
    final JButton go = new JButton("Show JColorChooser");
    go.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Color c;
            c = JColorChooser.showDialog(((Component) e.getSource()).getParent(), "Demo", Color.blue);
            contentPane.setBackground(c);
        }
    });
    contentPane.add(go, BorderLayout.SOUTH);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:net.lmxm.ute.gui.validation.AbstractInputValidator.java

/**
 * Gets the messages dialog./*from   www.j  a va2  s .  c o m*/
 * 
 * @return the messages dialog
 */
private JDialog getMessagesDialog() {
    if (messagesDialog == null) {
        messagesDialog = new JDialog();

        messagesDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        messagesDialog.setFocusableWindowState(false);
        messagesDialog.setUndecorated(true);

        final Container contentPane = messagesDialog.getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.setBackground(new Color(255, 250, 1));
        contentPane.add(getMessagesIcon());
        contentPane.add(getMessagesLabel());
    }

    return messagesDialog;
}

From source file:net.sf.jabref.gui.search.SearchBar.java

private void paintBackgroundWhite(Container container) {
    container.setBackground(Color.WHITE);
    for (Component component : container.getComponents()) {
        component.setBackground(Color.WHITE);

        if (component instanceof Container) {
            paintBackgroundWhite((Container) component);
        }/*from ww w. j  av a2  s .c om*/
    }
}

From source file:MouseWheelTest.java

public MouseWheelTest() {
    super();/*  w  ww.j  a  v  a2s  .  c  o  m*/
    final Container contentPane = getContentPane();

    MouseWheelListener listener = new MouseWheelListener() {
        int colorCounter;

        private static final int UP = 1;

        private static final int DOWN = 2;

        public void mouseWheelMoved(MouseWheelEvent e) {
            int count = e.getWheelRotation();
            int direction = (Math.abs(count) > 0) ? UP : DOWN;
            changeBackground(direction);
        }

        private void changeBackground(int direction) {
            contentPane.setBackground(colors[colorCounter]);

            if (direction == UP) {
                colorCounter++;
            } else {
                --colorCounter;
            }

            if (colorCounter == colors.length) {
                colorCounter = 0;
            } else if (colorCounter < 0) {
                colorCounter = colors.length - 1;
            }
        }
    };
    contentPane.addMouseWheelListener(listener);
}

From source file:com.diversityarrays.wizard.WizardRunner.java

protected void handleWizardEnded(WizardEndedReason reason) {

    if (handler != null) {
        handler.execute(reason);// w  w  w . j ava  2 s  .  co  m

    }

    status.setText(reason.toString());
    WizardRunner.this.setEnabled(false);

    RootPaneContainer rpc = ((RootPaneContainer) window);

    rpc.getContentPane().remove(this);

    Container cp = rpc.getContentPane();
    cp.removeAll();

    JLabel label = new JLabel(reason.toString());

    Box n = Box.createHorizontalBox();
    n.add(Box.createHorizontalGlue());
    n.add(label);
    n.add(Box.createHorizontalGlue());
    cp.add(n, BorderLayout.CENTER);

    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());
    box.add(new JButton(closeMe));
    box.add(Box.createHorizontalStrut(20));
    cp.add(box, BorderLayout.SOUTH);

    cp.setBackground(Color.LIGHT_GRAY);

    Dimension d = window.getSize();
    ++d.width;
    window.setSize(d);

}

From source file:ColorPicker3.java

public ColorPicker3() {
    super("JColorChooser Test Frame");
    setSize(200, 100);/*from  ww  w.  ja v  a2s  .c o  m*/
    final JButton go = new JButton("Show JColorChoser");
    final Container contentPane = getContentPane();
    go.addActionListener(new ActionListener() {
        final JColorChooser chooser = new JColorChooser();

        boolean first = true;

        public void actionPerformed(ActionEvent e) {
            if (first) {
                first = false;
                GrayScalePanel gsp = new GrayScalePanel();
                chooser.addChooserPanel(gsp);
                chooser.setPreviewPanel(new CustomPane());
            }
            JDialog dialog = JColorChooser.createDialog(ColorPicker3.this, "Demo 3", true, chooser,
                    new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            c = chooser.getColor();
                        }
                    }, null);
            dialog.setVisible(true);
            contentPane.setBackground(c);
        }
    });
    contentPane.add(go, BorderLayout.SOUTH);
    // addWindowListener(new BasicWindowMonitor()); // 1.1 & 1.2
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:model.DrawTopologyDiagram.java

@Override
public void init() {

    //create a graph
    Graph<VertexTopology, Number> ig = Graphs.<VertexTopology, Number>synchronizedDirectedGraph(
            new DirectedSparseMultigraph<VertexTopology, Number>());

    ObservableGraph<VertexTopology, Number> og = new ObservableGraph<VertexTopology, Number>(ig);
    og.addGraphEventListener(new GraphEventListener<VertexTopology, Number>() {

        public void handleGraphEvent(GraphEvent<VertexTopology, Number> evt) {
            System.err.println("got " + evt);

        }//w  w  w.jav  a  2s.  co m
    });
    this.g = og;
    //layouts
    //create a graphdraw
    //        layout = new FRLayout2<String,Number>(g);
    //        layout = new SpringLayout<String,Number>(g);
    //        ((FRLayout)layout).setMaxIterations(200);
    layout = new KKLayout<VertexTopology, Number>(g);

    vv = new VisualizationViewer<VertexTopology, Number>(layout, new Dimension(600, 600));

    createGraph();

    Container content = getContentPane();
    JPanel totalCasesPanel = new JPanel();

    final JPanel scaleGrids = new JPanel(new GridLayout(0, 2));
    scaleGrids.add(new JLabel("   Test Cases      "));
    scaleGrids.add(new JLabel("       "));
    totalCasesPanel.add(scaleGrids);

    JPanel filteredCasesPanel = new JPanel();

    final JPanel filteredGrids = new JPanel(new GridLayout(0, 2));
    filteredGrids.add(new JLabel("   Filtered Cases      "));
    filteredGrids.add(new JLabel("       "));
    filteredCasesPanel.add(filteredGrids);

    JRootPane rp = this.getRootPane();
    rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

    content.setLayout(new BorderLayout());
    content.setBackground(java.awt.Color.lightGray);
    content.setFont(new Font("Serif", Font.PLAIN, 12));

    vv.getModel().getRelaxer().setSleepTime(500);
    vv.setGraphMouse(new DefaultModalGraphMouse<VertexTopology, Number>());

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    vv.setForeground(Color.white);

    FontMetrics fm = vv.getFontMetrics(vv.getFont());
    int width = fm.stringWidth(g.toString());

    Transformer<VertexTopology, Shape> vertexSize = new Transformer<VertexTopology, Shape>() {
        public Shape transform(VertexTopology i) {

            Ellipse2D circle = new Ellipse2D.Double(-20, -20, 40, 40);
            // in this case, the vertex is twice as large                
            return circle;
        }

    };

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller() {
        @Override
        public String transform(Object v) {

            return ((VertexTopology) v).getScreenName();
        }
    });

    vv.getRenderContext().setVertexShapeTransformer(vertexSize);

    //Get picked states
    final PickedState<VertexTopology> pickedState = vv.getPickedVertexState();
    pickedState.addItemListener(new ItemListener() {
        ArrayList<TestCase> outputTestCase = new ArrayList<TestCase>();
        final Map<String, JButton> createdBtns = new HashMap<String, JButton>();

        Map<String, Integer> deviceSelected = new HashMap<String, Integer>(); // not useful

        ArrayList<String> endPointList = new ArrayList<String>();

        @Override
        public void itemStateChanged(ItemEvent e) {
            // TODO Auto-generated method stub
            Object subject = e.getItem();
            if (e.getStateChange() != 1) {
                scaleGrids.removeAll();
                filteredGrids.removeAll();
                endPointList.remove(getScreenName(subject));

                outputTestCase.clear();

                filteredGrids.repaint();
                filteredGrids.add(new JLabel("   Filtered Cases      "));
                filteredGrids.add(new JLabel("       "));

                scaleGrids.repaint();
                scaleGrids.add(new JLabel("   Test Cases      "));
                scaleGrids.add(new JLabel("       "));

                deviceSelected.clear();

            }
            if (e.getStateChange() == 1) {

                for (TestCase testCase : outputTestCase) {
                    scaleGrids.removeAll();
                    scaleGrids.add(new JLabel("   Test Cases      "));
                    scaleGrids.add(new JLabel("       "));

                    filteredGrids.removeAll();
                    filteredGrids.add(new JLabel("   Filtered Cases      "));
                    filteredGrids.add(new JLabel("       "));

                }

                if (subject instanceof VertexTopology) {
                    final VertexTopology edgePicked = (VertexTopology) subject;
                    if (pickedState.isPicked(edgePicked)) {

                        for (TestCase testCase : edgePicked.getTestCaseList()) {
                            if (!outputTestCase.contains(testCase))
                                outputTestCase.add(testCase);
                            System.out.println("The size for reference is " + testCase.inputReferenceMap.size()
                                    + testCase.getName());
                            System.out.println("The size for target is " + testCase.inputTargetMap.size()
                                    + testCase.getName());
                        }

                        if (deviceSelected.get(edgePicked.getScreenName()) != null)
                            deviceSelected.put(edgePicked.getScreenName(),
                                    deviceSelected.get(edgePicked.getScreenName()) + 1);
                        else
                            deviceSelected.put(edgePicked.getScreenName(), 1);

                        endPointList.add(edgePicked.getScreenName());

                    }
                }
            }

            for (TestCase testCase : outputTestCase) {
                JButton btnCase = new JButton(testCase.getName());
                scaleGrids.add(btnCase);

                if (testCase.getInputDeviceList().size() <= endPointList.size())
                    if (testCaseSelected(testCase, endPointList)) {
                        JButton btnCaseFiltered = new JButton(testCase.getName());
                        filteredGrids.add(btnCaseFiltered);
                    }
                ;

            }

            scaleGrids.revalidate();
            scaleGrids.setVisible(true);
        }

    });

    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    vv.setGraphMouse(graphMouse);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    content.setPreferredSize(new Dimension(1400, 900));
    content.add(vv);
    switchLayout = new JButton("Switch to SpringLayout");
    //        switchLayout.addActionListener(new ActionListener() {
    //
    //            @SuppressWarnings("unchecked")
    //            public void actionPerformed(ActionEvent ae) {
    //               Dimension d = new Dimension(600,600);
    //                if (switchLayout.getText().indexOf("Spring") > 0) {
    //                    switchLayout.setText("Switch to FRLayout");
    //                    layout = new SpringLayout<String,Number>(g,
    //                        new ConstantTransformer(EDGE_LENGTH));
    //                    layout.setSize(d);
    //                    vv.getModel().setGraphLayout(layout, d);
    //                } else {
    //                    switchLayout.setText("Switch to SpringLayout");
    //                    layout = new FRLayout<String,Number>(g, d);
    //                    vv.getModel().setGraphLayout(layout, d);
    //                }
    //            }
    //        });

    JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, totalCasesPanel, filteredCasesPanel);
    jSplitPane.setResizeWeight(.5d);

    content.add(switchLayout, BorderLayout.SOUTH);
    content.add(jSplitPane, BorderLayout.EAST);
}

From source file:com.maxl.java.amikodesk.AMiKoDesk.java

private static void createAndShowLightGUI() {
    // Create and setup window
    final JFrame jframe = new JFrame(Constants.APP_NAME);
    int min_width = CML_OPT_WIDTH;
    int min_height = CML_OPT_HEIGHT;

    jframe.setPreferredSize(new Dimension(min_width, min_height));
    jframe.setMinimumSize(new Dimension(min_width, min_height));
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - min_width) / 2;
    int y = (screen.height - min_height) / 2;
    jframe.setBounds(x, y, min_width, min_height);

    // Action listeners
    jframe.addWindowListener(new WindowListener() {
        // Use WindowAdapter!
        @Override//from  w  w w .  j av a  2 s .  co  m
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
            m_web_panel.dispose();
            Runtime.getRuntime().exit(0);
        }

        @Override
        public void windowClosing(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });

    // Container
    final Container container = jframe.getContentPane();
    container.setBackground(Color.WHITE);
    container.setLayout(new BorderLayout());

    // ==== Light panel ====
    JPanel light_panel = new JPanel();
    light_panel.setBackground(Color.WHITE);
    light_panel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(2, 2, 2, 2);

    // ---- Section titles ----
    m_section_titles = null;
    if (Utilities.appLanguage().equals("de")) {
        m_section_titles = new IndexPanel(SectionTitle_DE);
    } else if (Utilities.appLanguage().equals("fr")) {
        m_section_titles = new IndexPanel(SectionTitle_FR);
    }
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 8;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(m_section_titles, gbc);
    if (m_section_titles != null)
        light_panel.add(m_section_titles, gbc);

    // ---- Fachinformation ----
    m_web_panel = new WebPanel2();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridwidth = 3;
    gbc.gridheight = 20;
    gbc.weightx = 2.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.EAST;
    // --> container.add(m_web_panel, gbc);
    light_panel.add(m_web_panel, gbc);

    // ---- Add panel to main container ----
    container.add(light_panel, BorderLayout.CENTER);

    // Display window
    jframe.pack();
    // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    // jframe.setAlwaysOnTop(true);
    jframe.setVisible(true);

    // If command line options are provided start app with a particular
    // title or eancode
    if (commandLineOptionsProvided()) {
        final JToggleButton but_dummy = new JToggleButton("dummy_button");
        if (!CML_OPT_TITLE.isEmpty())
            startAppWithTitle(but_dummy);
        else if (!CML_OPT_EANCODE.isEmpty())
            startAppWithEancode(but_dummy);
        else if (!CML_OPT_REGNR.isEmpty())
            startAppWithRegnr(but_dummy);
        else if (CML_OPT_SERVER == true) {
            // Start thread that reads data from TCP server
            Thread server_thread = new Thread() {
                public void run() {
                    while (true) {
                        String tcpServerInput = "";
                        // Wait until new data is available from input stream
                        // Note: the TCP client defines the update rate!
                        // System.out.print("Waiting for input...");
                        while ((tcpServerInput = mTcpServer.getInput()).isEmpty())
                            ;
                        /*
                         * Important note: we use invokeLater to post a "job" to Swing, which will then be run on the
                         * event dispatch thread at Swing's next convenience. Failing to do so will freeze the main thread.
                         */

                        // Detect type of search (t=title, e=eancode, r=regnr)
                        char typeOfSearch = tcpServerInput.charAt(0);
                        if (typeOfSearch == 't') {
                            // Extract title from received string
                            CML_OPT_TITLE = tcpServerInput.substring(2);
                            // System.out.println(" title -> " +
                            // CML_OPT_TITLE);
                            // Post a "job" to Swing, which will be run on
                            // the event dispatch thread
                            // at its next convenience.
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    startAppWithTitle(but_dummy);
                                }
                            });
                        } else if (typeOfSearch == 'e') {
                            // Extract ean code from received string
                            CML_OPT_EANCODE = tcpServerInput.substring(2);
                            // System.out.println(" eancode -> " +
                            // CML_OPT_EANCODE);
                            // Post a "job" to Swing, which will be run on
                            // the event dispatch thread
                            // at its next convenience.
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    startAppWithEancode(but_dummy);
                                }
                            });
                        } else if (typeOfSearch == 'r') {
                            // Extract registration number from received
                            // string
                            CML_OPT_REGNR = tcpServerInput.substring(2);
                            // System.out.println(" regnr -> " +
                            // CML_OPT_REGNR);
                            // Post a "job" to Swing, which will be run on
                            // the event dispatch thread
                            // at its next convenience.
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    startAppWithRegnr(but_dummy);
                                }
                            });
                        }
                    }
                }
            };
            server_thread.start();
        }
    }
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.xhtml.PainelXHTML.java

private void criaInterfaceVisualEscalavel() {
    painel = new JPanel();
    textAreaSourceCode = new G_TextAreaSourceCode();
    new OnChange(textAreaSourceCode, this);
    // textAreaSourceCode.getTextPane().addKeyListener(this);

    textAreaSourceCode.setTipoHTML();/*  w w w.  j  av a  2  s .  c o m*/
    textAreaSourceCode.setBorder(criaBorda(XHTML_Panel.COD_FONTE));
    // frameSilvinha.setTitle(XHTMLPanel.TITULO);
    // this.frameSilvinha.setTitle(XHTMLPanel.TITULO_XHTML);

    painel.setLayout(new GridLayout(2, 1));
    setBackground(frameSilvinha.corDefault);

    Container contentPane = this;
    contentPane.setLayout(new GridLayout(1, 1));
    painel.add(textAreaSourceCode);

    JPanel panelBtnTabela = new JPanel();

    panelBtnTabela.setLayout(new BorderLayout());

    /*
     * Barra de botes
     */
    btnPanel = new JPanel();
    btnPanel.setLayout(null);
    btn_salvar = new JButton(XHTML_Panel.BTN_SALVAR);
    btn_salvar.setBounds(10, 0, 140, 25);
    btnPanel.add(btn_salvar);

    btn_abrir = new JButton(XHTML_Panel.BTN_ABRIR);
    btn_abrir.setBounds(165, 0, 150, 25);
    btnPanel.add(btn_abrir);

    btn_salvarComo = new JButton(XHTML_Panel.BTN_SALVAR_COMO);
    btn_salvarComo.setBounds(325, 0, 150, 25);
    btnPanel.add(btn_salvarComo);

    btnPanel.setPreferredSize(new Dimension(760, 30));

    btn_cancelar = new JButton(GERAL.TELA_ANTERIOR);
    btn_cancelar.setBounds(485, 0, 150, 25);
    btnPanel.add(btn_cancelar);

    tabelaDeErros = new TabelaErros();
    scrollPaneTabela = new JScrollPane();
    scrollPaneTabela.setViewportView(tabelaDeErros);
    panelBtnTabela.add(btnPanel, BorderLayout.NORTH);
    panelBtnTabela.add(scrollPaneTabela, BorderLayout.CENTER);
    scrollPaneTabela.setBorder(criaBorda(XHTML_Panel.LISTA_ERROS));
    painel.add(panelBtnTabela);

    btnPanel.setBackground(frameSilvinha.corDefault);

    reverter = new JButton("Reverter");
    reverter.setText(TradPainelRelatorio.REVERTER);
    reverter.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            setVisible(false);
            TxtBuffer.setContent(TxtBuffer.getContentOriginal());
            frameSilvinha.showPainelFerramentaXHTML();
            setVisible(true);
        }

    });
    //reverter.setActionCommand("Reverter");
    reverter.setToolTipText(TradPainelRelatorio.DICA_REVERTER);
    reverter.getAccessibleContext().setAccessibleDescription(TradPainelRelatorio.DICA_REVERTER);
    reverter.getAccessibleContext().setAccessibleName(TradPainelRelatorio.DICA_REVERTER);
    reverter.setBounds(650, 0, 150, 25);
    btnPanel.add(reverter);

    panelBtnTabela.setBackground(frameSilvinha.corDefault);
    painel.setBackground(frameSilvinha.corDefault);
    contentPane.setBackground(frameSilvinha.corDefault);
    scrollPaneTabela.setBackground(frameSilvinha.corDefault);
    textAreaSourceCode.setBackground(frameSilvinha.corDefault);
    miBtnSalvar.setEnabled(false);
    btn_salvar.setEnabled(false);

    contentPane.add(painel);
    // pack();
    this.setVisible(true);
}