congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Component.setBackground
Code IndexAdd Tabnine to your IDE (free)

How to use
setBackground
method
in
java.awt.Component

Best Java code snippets using java.awt.Component.setBackground (Showing top 20 results out of 1,341)

Refine searchRefine arrow

  • Window.setVisible
  • Container.add
  • JFrame.setDefaultCloseOperation
  • JFrame.getContentPane
  • JFrame.<init>
origin: stackoverflow.com

 import java.awt.*;
import javax.swing.*;

class FixedSizeContent {
  public static void main(String[] args) {
    SwingUtilities.invokeLater( new Runnable() {
      public void run() {
        JFrame f = new JFrame("Fixed size content");
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Container c = f.getContentPane();
        c.setBackground(Color.YELLOW);
        // adjust to need.
        Dimension d = new Dimension(400,40);
        c.setPreferredSize(d);
        f.pack();
        f.setResizable(false);
        f.setVisible(true);
      }
    });
  }
}
origin: stackoverflow.com

if (useSlideButton) {
  final JPanel statusPanel = new JPanel();
  basePanel.add(statusPanel, BorderLayout.SOUTH);
  statusPanel.add(new JButton("Slide Left") {
    private static final long serialVersionUID = 9204819004142223529L;
  statusPanel.add(new JButton("Slide Right") {
if (w instanceof JFrame) {
  final JFrame j = (JFrame) w;
  if (j.getContentPane().getComponents().length > 0) {
    throw new RuntimeException("ProgramCheck: Parent already contains content.");
  j.getContentPane().add(basePanel);
  ((JFrame) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
  parent.remove(basePanel);
  parent.validate();
  ((JDialog) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
  parent.remove(basePanel);
  parent.validate();
  ((JWindow) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
  parent.remove(basePanel);
  parent.validate();
origin: stackoverflow.com

import java.applet.*;
import java.awt.*;
public class JavaVersionDisplayApplet extends Applet
{ private Label m_labVersionVendor; 
 public JavaVersionDisplayApplet() //constructor
 { Color colFrameBackground = Color.pink;
  this.setBackground(colFrameBackground);
  m_labVersionVendor = new Label (" Java Version: " +
                 System.getProperty("java.version")+
             " from "+System.getProperty("java.vendor"));
  this.add(m_labVersionVendor);
 }
}
origin: stackoverflow.com

cd.setBackground(Color.BLUE);
add(cd);
g.setVisible(true);
origin: stackoverflow.com

 import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;

public class Frames extends JFrame {
  private static final long serialVersionUID = 1L;

  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          new Frames();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }

  public Frames() {
    setSize(new Dimension(100, 100));
    setTitle("MAIN MENU");
    getContentPane().setBackground(Color.YELLOW);
    setVisible(true);
  }

}
origin: stackoverflow.com

final JFrame frame = new JFrame("Image Manipulation Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.BLUE.darker());
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel(new ImageIcon(ORIGINAL)));
frame.getContentPane().add(new JLabel(new ImageIcon(ALTERED)));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
origin: stackoverflow.com

panel.setBackground(Color.cyan.darker());
add(panel);
pack(); 
setVisible(true);
origin: stackoverflow.com

 import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Label;

/**
 *
 * @author hmmmmm
 */
public class MessageApplet extends Applet {

  private Label m_mess;

  public void init() {
    setBackground(Color.lightGray);
    setLayout(new BorderLayout());
    m_mess = new Label("MessageApplet is Running... : No Selection Yet", Label.CENTER);
    add(BorderLayout.CENTER, m_mess);
    m_mess.setBackground(Color.red);
  }

  public void setMessage(String message) {
    m_mess.setText("Selection : " + message);
  }
}
origin: stackoverflow.com

 import java.awt.Color;
import javax.swing.JFrame;

public class BFrame {

  public static void main(String[] args) {
    new JFrame() {{
      super.setBackground(Color.CYAN);
      this.getRootPane().setBackground(Color.BLUE);
      this.getLayeredPane().setBackground(Color.RED);
      this.getContentPane().setBackground(Color.YELLOW);
      this.setSize(400,340); 
      this.setVisible(true);
    }};
  }
}
origin: stackoverflow.com

JFrame f = new JFrame();
f.setLayout(new FlowLayout());
f.getContentPane().setBackground(new Color(0xffffc0));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.add(new TransparentTextArea(0));
jif.add(panel);
jif.setVisible(true);
f.add(jif);
f.pack();
f.setVisible(true);
origin: stackoverflow.com

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLocationByPlatform(true);
window.setVisible(true);
setSize(iWidth, iHeight);
getContentPane().setBackground(pInterfaceColour);
pGradientPane = new JPanel() {
  private static final long serialVersionUID = 1L;
pGradientPane.setPreferredSize(new Dimension(iWidth - 16, iHeight - 62));
add(pGradientPane);
origin: stackoverflow.com

private JFrame f = new JFrame("Colors");
private static final String ITEMS[] = {" black ", " blue ", " green ",
  " orange ", " purple ", " red ", " white ", " yellow "};
    checkBoxes[i].addItemListener(this);
    enabledFlags[i] = true;
    pnlEnablers.add(checkBoxes[i]);
  scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
      f.setVisible(true);
      if (isSelected & cellHasFocus) {
        comp.setForeground(Color.black);
        comp.setBackground(Color.red);
      } else {
        comp.setForeground(Color.blue);
        if ((value.toString()).trim().equals("yellow")) {
          comp.setForeground(Color.orange);
          comp.setBackground(Color.magenta);
origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setTitle("Test Background");
frame.setLocation(200, 100);
frame.getContentPane().setBackground(Color.BLUE);
frame.setVisible(true);
origin: stackoverflow.com

JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.yellow);
frame.getContentPane().add(button);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(150, 150);
frame.setVisible(true);
origin: stackoverflow.com

private JFrame frame = new JFrame("Frame");
private JPanel fatherCenter = new JPanel();
private JScrollPane tableScroll = new JScrollPane();
        comp.setForeground(Color.black);
        if ((type) && (!type1)) {
          comp.setBackground(Color.yellow);
        } else if ((!type) && (type1)) {
          comp.setBackground(Color.orange);
        } else if ((!type) || (!type1)) {
          comp.setBackground(Color.red);
          comp.setBackground(row % 2 == 0 ? getBackground() : getBackground().darker());
        comp.setBackground(Color.lightGray);
        comp.setBackground(Color.magenta);
  fatherCenter.add(tableScroll, BorderLayout.CENTER);
  pane.add(fatherCenter);
origin: stackoverflow.com

JFrame f = new JFrame( frameTitle );
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 150);
Container content = f.getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout()); 
content.add(new JLabel("Initializing ... "));
f.setVisible(true);
f.setVisible(true);
origin: stackoverflow.com

 import java.awt.Canvas;
import java.awt.Color;
import javax.swing.JFrame;

public class test {
  static JFrame frame;
  static Canvas canvas;

  public static void main(String[] args){
    frame  = new JFrame();
    canvas = new Canvas();

    canvas.setBackground(Color.cyan);
    frame.getContentPane().add(canvas);
    frame.setVisible(true);
  }
}
origin: stackoverflow.com

 import java.awt.*;
import javax.swing.*;

public class TestUnderscore 
{
 // Test routine.
 public static void main(String[] args) 
 {
  JFrame frame = new JFrame();
  frame.getContentPane().setBackground(Color.yellow);
  frame.getContentPane().add(new JLabel("Test_Underscore$$"));
  frame.getContentPane().setLayout(new FlowLayout());
  frame.setSize(450, 450);
  frame.setVisible(true);
 }
}
origin: stackoverflow.com

 import javax.swing.*;
import java.awt.*;

public class CustomComponent extends JFrame {

private static final long serialVersionUID = 1L;

public CustomComponent() {

}

public static void main(String[] args) {
  JFrame frame = new JFrame("Java Rulez");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setBounds(100,100,600,600);
  frame.getContentPane().setBackground(Color.YELLOW);

  frame.add(new RectangleComponent(0, 0, 500, 500));

  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
}
origin: stackoverflow.com

 import javax.swing.JFrame;
import java.awt.Color;
import java.awt.EventQueue;

public class ColoredFrame {

 public static void main( String[] args ) {
  EventQueue.invokeLater( new Runnable() {
   @Override
   public void run() {
    JFrame frame = new JFrame( "TestFrame" );
    frame.getContentPane().setBackground( Color.PINK );
    //frame contains nothing, so set size
    frame.setSize( 200, 200 );
    frame.setVisible( true );
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
   }
  } );
 }
}
java.awtComponentsetBackground

Javadoc

Sets the background color of this component.

The background color affects each component differently and the parts of the component that are affected by the background color may differ between operating systems.

Popular methods of Component

  • getParent
    Gets the parent of this component.
  • getPreferredSize
    Gets the preferred size of this component.
  • getHeight
    Returns the current height of this component. This method is preferable to writingcomponent.getBound
  • getWidth
    Returns the current width of this component. This method is preferable to writingcomponent.getBounds
  • isVisible
    Determines whether this component should be visible when its parent is visible. Components are initi
  • setBounds
    Moves and resizes this component to conform to the new bounding rectangle r. This component's new po
  • getName
    Gets the name of the component.
  • getSize
    Stores the width/height of this component into "return value" rv and return rv. If rv is null a newD
  • setEnabled
    Enables or disables this component, depending on the value of the parameter b. An enabled component
  • setVisible
    Shows or hides this component depending on the value of parameterb.
  • getMinimumSize
    Gets the mininimum size of this component.
  • getBackground
    Gets the background color of this component.
  • getMinimumSize,
  • getBackground,
  • addMouseListener,
  • getBounds,
  • setForeground,
  • repaint,
  • setCursor,
  • setSize,
  • requestFocus

Popular in Java

  • Running tasks concurrently on multiple threads
  • getResourceAsStream (ClassLoader)
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now