Tabnine Logo
Component.getBackground
Code IndexAdd Tabnine to your IDE (free)

How to use
getBackground
method
in
java.awt.Component

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

Refine searchRefine arrow

  • Window.setVisible
  • Container.add
  • JFrame.setDefaultCloseOperation
  • JFrame.<init>
  • JComponent.setBackground
  • Window.pack
origin: stackoverflow.com

JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
  add(cellPane, gbc);
@Override
public void mouseEntered(MouseEvent e) {
  defaultBackground = getBackground();
  setBackground(Color.BLUE);
  setBackground(defaultBackground);
origin: stackoverflow.com

  JPanel gui = new JPanel(new GridLayout(2,0,5,5));
  gui.setBorder(new EmptyBorder(10,10,10,10));
  gui.setBackground(Color.RED);
  gui.add(l1);
  l2.setBackground(Color.YELLOW);
  l2.setOpaque(true);
  gui.add(l2);
  p1.add(new JLabel("Panel 1"));
  p1.setBorder(brdrRight);
  p1.setOpaque(false);
Color bg = parent.getBackground();
Rectangle rect = new Rectangle(0,0,width, height);
Area borderRegion = new Area(rect);
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") {
  ((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

JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TestPane());
g2d.setColor(c.getBackground());
g2d.fill(area);
origin: stackoverflow.com

JFrame frame = new JFrame("JAVA");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComboBox cmb = new JComboBox(strings);
ComboBoxRenderer renderer = new ComboBoxRenderer(cmb);
frame.add(cmb);
frame.pack();
frame.setVisible(true);
textPanel.add(this);
text = new JLabel();
text.setOpaque(true);
text.setFont(combo.getFont());
textPanel.add(text);
  setBackground(list.getSelectionBackground());
  setBackground(Color.WHITE);
text.setBackground(getBackground());
origin: stackoverflow.com

 public static void main(String[] args) {
  final JFrame jf = new JFrame();
  jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  final Grid grid = new Grid();
  jf.add(grid);
  jf.pack();
  jf.addWindowListener(new WindowAdapter() {
    public void windowActivated(WindowEvent e) {
      int i = 0;
      Component[] components = grid.getComponents();
      for (Component component : components) {
        i++;
        Color color = component.getBackground();
        Rectangle bounds = component.getBounds();
        System.out.println("box " + i + ",coordinate= " + bounds
            + ", Color= " + color);
      }
    }
  });
  jf.setVisible(true);
}
origin: stackoverflow.com

final JPanel panel = new JPanel(new GridBagLayout()) {
    setBackground(Color.RED);
button.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e) {
    if (panel.getBackground() == Color.RED) {
      System.out.println("RED");
      panel.setBackground(Color.GREEN);
    } else if (panel.getBackground() == Color.GREEN) {
      System.out.println("GREEN");
      panel.setBackground(Color.RED);
panel.add(button);
JOptionPane.showMessageDialog(null, panel);
origin: net.imagej/imagej-ui-swing

public static JScrollPane scrollPane(final Component component,
  final int width, final int height, final Container addTo)
{
  final JScrollPane scroll = new JScrollPane(component);
  scroll.getViewport().setBackground(component.getBackground());
  scroll.setPreferredSize(new Dimension(width, height));
  if (addTo != null) addTo.add(scroll);
  return scroll;
}
origin: stackoverflow.com

    g.setColor(hoverBackgroundColor);
  } else {
    g.setColor(getBackground());
JFrame frame = new JFrame("Test button");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final MyButton btnSave = new MyButton("Save");
btnSave.setForeground(new Color(0, 135, 200).brighter());
btnSave.setHorizontalTextPosition(SwingConstants.CENTER);
btnSave.setBorder(null);
btnSave.setBackground(new Color(3, 59, 90));
btnSave.setHoverBackgroundColor(new Color(3, 59, 90).brighter());
btnSave.setPressedBackgroundColor(Color.PINK);
frame.add(btnSave);
frame.setSize(200, 200);
frame.setVisible(true);
origin: stackoverflow.com

 g.setColor(getBackground());
button.setBackground(Color.green);
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

control.setLayout(new GridLayout(0, 1));
for (CabPanel cp : fleet) {
  control.add(cp);
  timer.addActionListener(cp.listener);
this.add(map, BorderLayout.CENTER);
this.add(control, BorderLayout.SOUTH);
  super(new GridLayout(1, 0));
  name.setText(s);
  this.setBackground(hue.getColor());
  this.add(map, BorderLayout.CENTER);
  for (Hue h : Hue.values()) {
    public void actionPerformed(ActionEvent e) {
      Hue h = (Hue) colorBox.getSelectedItem();
      CabPanel.this.setBackground(h.getColor());
      update();
  this.setBackground(Color.lightGray);
    int x = SIZE * (p.x + w / 2 / SIZE) - SIZE / 2;
    int y = SIZE * (p.y + h / 2 / SIZE) - SIZE / 2;
    g2d.setColor(cp.getBackground());
    g2d.fillOval(x, y, SIZE, SIZE);
origin: stackoverflow.com

final JFrame frame = new JFrame("Image zoom");
frame.getContentPane().add(zoomPanel);
final Ticker t = new Ticker(zoomPanel);
frame.pack();
frame.setVisible(true);
g2.setColor(getBackground());
try {
origin: stackoverflow.com

private JFrame frame = new JFrame("Frame");
private JPanel fatherCenter = new JPanel();
private JScrollPane tableScroll = new JScrollPane();
          comp.setBackground(row % 2 == 0 ? getBackground() : getBackground().darker());
  fatherCenter.add(tableScroll, BorderLayout.CENTER);
  pane.add(fatherCenter);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout(10, 10));
  addComponentsToPane(frame.getContentPane());
  frame.setLocation(150, 150);
  frame.setPreferredSize(new Dimension(400, 647));
  frame.pack();
  frame.setVisible(true);
origin: stackoverflow.com

JFrame frame = new JFrame("Image panel");
frame.setSize(800, 300);
frame.setLocationByPlatform(true);
JList imageList = createImageList();
frame.getContentPane().add(new JScrollPane(imageList));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
  imageLabel.setBorder(emptyBorder);
  descriptionLabel.setBorder(emptyBorder);
  add(imageLabel, BorderLayout.CENTER);
  add(descriptionLabel, BorderLayout.SOUTH);
  defaultListCellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  setBorder(defaultListCellRenderer.getBorder());
  setBackground(defaultListCellRenderer.getBackground());
  imageLabel.setIcon((Icon)value);
  descriptionLabel.setText("Description");
origin: stackoverflow.com

JFrame frame = new JFrame("JButtonTable Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(scroll);
frame.pack();
frame.setVisible(true);
if (isSelected) {
  setForeground(table.getSelectionForeground());
  setBackground(table.getSelectionBackground());
} else {
  setForeground(table.getForeground());
  setBackground(UIManager.getColor("Button.background"));
if (isSelected) {
  button.setForeground(table.getSelectionForeground());
  button.setBackground(table.getSelectionBackground());
} else {
  button.setForeground(table.getForeground());
  button.setBackground(table.getBackground());
origin: stackoverflow.com

s.getViewport().add(m_tree);
getContentPane().add(s, BorderLayout.CENTER);
setVisible(true);
setForeground(sel ? m_textSelectionColor : 
  m_textNonSelectionColor);
setBackground(sel ? m_bkSelectionColor : 
  m_bkNonSelectionColor);
m_selected = sel;
Color bColor = getBackground();
Icon icon = getIcon();
origin: stackoverflow.com

  label.setForeground(isSelected? list.getSelectionForeground()
                 : list.getForeground());
  p.add(icon);
  p.add(label, BorderLayout.SOUTH);
  p.setBackground(isSelected? list.getSelectionBackground()
               : list.getBackground());
  return p;
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new DragAndDropTest().makeUI());
f.setSize(320, 240);
f.setLocationRelativeTo(null);
f.setVisible(true);
origin: stackoverflow.com

private JFrame frame = new JFrame("Navigation Filter Example");
private JPanel panel = new JPanel();
private JLabel label = new JLabel(" $ ");
  panel.setBackground(textField.getBackground());
  panel.setLayout(new BorderLayout());
  panel.add(label,BorderLayout.WEST);
  textField.setBorder(null);
  panel.add(textField,BorderLayout.CENTER);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().add(panel);
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
origin: stackoverflow.com

 import java.awt.*;  
import javax.swing.*;  
class Testing extends JFrame  
{  
 public Testing()  
 {  
  setDefaultCloseOperation(EXIT_ON_CLOSE);  
  JPanel p = new JPanel(new BorderLayout());  
  JTextField tf = new JTextField(5);  
  JLabel label = new JLabel(new ImageIcon("Test.gif"));  
  label.setOpaque(true);  
  label.setBackground(tf.getBackground());  
  label.setPreferredSize(new Dimension(label.getPreferredSize().width,tf.getPreferredSize().height));  
  p.setBorder(tf.getBorder());  
  tf.setBorder(null);  
  p.add(label,BorderLayout.WEST);  
  p.add(tf,BorderLayout.CENTER);  
  JPanel p1 = new JPanel();  
  p1.add(p);  
  getContentPane().add(p1);  
  pack();  
  setLocationRelativeTo(null);  
 }  
 public static void main(String[] args){new Testing().setVisible(true);}  
}
origin: stackoverflow.com

 import java.awt.*;  
import javax.swing.*;  
class Testing extends JFrame  
{  
 public Testing()  
 {  
  setDefaultCloseOperation(EXIT_ON_CLOSE);  
  JPanel p = new JPanel(new BorderLayout());  
  JTextField tf = new JTextField(5);  
  JLabel label = new JLabel(new ImageIcon("Test.gif"));  
  label.setOpaque(true);  
  label.setBackground(tf.getBackground());  
  label.setPreferredSize(new Dimension(label.getPreferredSize().width,tf.getPreferredSize().height));  
  p.setBorder(tf.getBorder());  
  tf.setBorder(null);  
  p.add(label,BorderLayout.WEST);  
  p.add(tf,BorderLayout.CENTER);  
  JPanel p1 = new JPanel();  
  p1.add(p);  
  getContentPane().add(p1);  
  pack();  
  setLocationRelativeTo(null);  
 }  
 public static void main(String[] args){new Testing().setVisible(true);}  
}
java.awtComponentgetBackground

Javadoc

Gets the background color of this component.

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
  • setBackground
    Sets the background color of this component. The background color affects each component differently
  • setVisible
    Shows or hides this component depending on the value of parameterb.
  • getMinimumSize
    Gets the mininimum size of this component.
  • setVisible,
  • getMinimumSize,
  • addMouseListener,
  • getBounds,
  • setForeground,
  • repaint,
  • setCursor,
  • setSize,
  • requestFocus

Popular in Java

  • Running tasks concurrently on multiple threads
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • compareTo (BigDecimal)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top PhpStorm plugins
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