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); } }); } }
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();
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); } }
cd.setBackground(Color.BLUE); add(cd); g.setVisible(true);
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); } }
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);
panel.setBackground(Color.cyan.darker()); add(panel); pack(); setVisible(true);
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); } }
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); }}; } }
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);
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);
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);
JFrame frame = new JFrame(); frame.setTitle("Test Background"); frame.setLocation(200, 100); frame.getContentPane().setBackground(Color.BLUE); frame.setVisible(true);
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);
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);
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);
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); } }
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); } }
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); } }
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 ); } } ); } }