Java Code Examples for java.awt.Container#setBackground()

The following examples show how to use java.awt.Container#setBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlatRootPaneUI.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
protected void installDefaults( JRootPane c ) {
	super.installDefaults( c );

	// Update background color of JFrame or JDialog parent to avoid bad border
	// on HiDPI screens when switching from light to dark Laf.
	// The background of JFrame is initialized in JFrame.frameInit() and
	// the background of JDialog in JDialog.dialogInit(),
	// but it was not updated when switching Laf.
	Container parent = c.getParent();
	if( parent instanceof JFrame || parent instanceof JDialog ) {
		Color background = parent.getBackground();
		if( background == null || background instanceof UIResource )
			parent.setBackground( UIManager.getColor( "control" ) );
	}

	// enable dark window appearance on macOS when running in JetBrains Runtime
	if( SystemInfo.IS_JETBRAINS_JVM && SystemInfo.IS_MAC_OS_10_14_MOJAVE ) {
		LookAndFeel laf = UIManager.getLookAndFeel();
		boolean isDark = laf instanceof FlatLaf && ((FlatLaf)laf).isDark();
		c.putClientProperty( "jetbrains.awt.windowDarkAppearance", isDark );
	}
}
 
Example 2
Source File: SlowPanelIteration.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void showUI() {
    frame = new JFrame();
    frame.setSize(new Dimension(400, 400));
    frame.setLocationRelativeTo(null);

    final Container content = frame.getContentPane();
    content.setLayout(new BorderLayout(0, 0));
    Container lastPanel = content;
    for (int i = 0; i < 500; i++) {
        final JPanel p = new JPanel();
        p.setLayout(new BorderLayout(0, 0));
        lastPanel.add(p);
        lastPanel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("click");
                go.countDown();
            }
        });
        lastPanel = p;
    }

    lastPanel.setBackground(Color.GREEN);
    frame.setVisible(true);

    Point loc = frame.getLocationOnScreen();
    center.x = loc.x + frame.getWidth() / 2;
    center.y = loc.y + frame.getHeight() / 2;
}
 
Example 3
Source File: SlowPanelIteration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void showUI() {
    frame = new JFrame();
    frame.setSize(new Dimension(400, 400));
    frame.setLocationRelativeTo(null);

    final Container content = frame.getContentPane();
    content.setLayout(new BorderLayout(0, 0));
    Container lastPanel = content;
    for (int i = 0; i < 500; i++) {
        final JPanel p = new JPanel();
        p.setLayout(new BorderLayout(0, 0));
        lastPanel.add(p);
        lastPanel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("click");
                go.countDown();
            }
        });
        lastPanel = p;
    }

    lastPanel.setBackground(Color.GREEN);
    frame.setVisible(true);

    Point loc = frame.getLocationOnScreen();
    center.x = loc.x + frame.getWidth() / 2;
    center.y = loc.y + frame.getHeight() / 2;
}
 
Example 4
Source File: ChatWindow.java    From CPE552-Java with GNU General Public License v3.0 5 votes vote down vote up
public ChatWindow(int w, int h, Color bg) {
   super("Stevens Chat"); 
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   Container c = getContentPane();
   c.setBackground(bg);
   setSize(w,h);
   Font f = new Font("Times", Font.PLAIN, 24);
   JButton b = new JButton("ok");
   b.setFont(f);
   c.add(b, BorderLayout.NORTH);
   
   JTextField t = new JTextField("testing testing 123");
   t.setFont(f);
   c.add(t, BorderLayout.SOUTH);
   
   JPanel p = new JPanel();
   p.setBackground(new Color(100, 0, 150));
   p.setLayout(new GridLayout(3, 3, 5, 10));
   String[] names = { "x", "y", "testing", "hello", "大", "a", "b", "c", "d"};
   for (int i = 0; i < 9; i++) {
      b = new JButton(names[i]);
      p.add(b);
       
   }
   c.add(p, BorderLayout.CENTER);
   
   
   setVisible(true); 
}
 
Example 5
Source File: Win2.java    From CPE552-Java with GNU General Public License v3.0 5 votes vote down vote up
public Win2(String title, int w, int h, Color bg) {
   super(title); // calls JFrame(String title)
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   Container c = getContentPane();
   c.setBackground(bg);
   setSize(w,h);
   setVisible(true); 
}
 
Example 6
Source File: SlowPanelIteration.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void showUI() {
    frame = new JFrame();
    frame.setSize(new Dimension(400, 400));
    frame.setLocationRelativeTo(null);

    final Container content = frame.getContentPane();
    content.setLayout(new BorderLayout(0, 0));
    Container lastPanel = content;
    for (int i = 0; i < 500; i++) {
        final JPanel p = new JPanel();
        p.setLayout(new BorderLayout(0, 0));
        lastPanel.add(p);
        lastPanel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("click");
                go.countDown();
            }
        });
        lastPanel = p;
    }

    lastPanel.setBackground(Color.GREEN);
    frame.setVisible(true);

    Point loc = frame.getLocationOnScreen();
    center.x = loc.x + frame.getWidth() / 2;
    center.y = loc.y + frame.getHeight() / 2;
}
 
Example 7
Source File: SlowPanelIteration.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void showUI() {
    frame = new JFrame();
    frame.setSize(new Dimension(400, 400));
    frame.setLocationRelativeTo(null);

    final Container content = frame.getContentPane();
    content.setLayout(new BorderLayout(0, 0));
    Container lastPanel = content;
    for (int i = 0; i < 500; i++) {
        final JPanel p = new JPanel();
        p.setLayout(new BorderLayout(0, 0));
        lastPanel.add(p);
        lastPanel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("click");
                go.countDown();
            }
        });
        lastPanel = p;
    }

    lastPanel.setBackground(Color.GREEN);
    frame.setVisible(true);

    Point loc = frame.getLocationOnScreen();
    center.x = loc.x + frame.getWidth() / 2;
    center.y = loc.y + frame.getHeight() / 2;
}
 
Example 8
Source File: CreditsDialog.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the GUI.
 *
 * @param owner parent window
 */
private void initGUI(final Frame owner) {
	this.addWindowListener(new WindowAdapter() {
		@Override
		public void windowClosing(WindowEvent e) {
			owner.setEnabled(true);
			dispose();
		}
	});
	owner.setEnabled(false);
	Container content = this.getContentPane();
	if (content instanceof JComponent) {
		((JComponent) content).setBorder(null);
	}
	// Colors
	Color backgroundColor = Color.white;
	Color textColor = new Color(85, 85, 85);

	content.setLayout(new BorderLayout());
	content.setBackground(backgroundColor);

	// read the credits from an external file because code format gets it
	// unreadable if inlined
	final List<String> creditsList = readCredits();
	Font textFont = new Font("SansSerif", Font.BOLD, 12);
	sp = new ScrollerPanel(creditsList, textFont, 0, textColor,
			backgroundColor, 20);

	JPanel buttonPane = new JPanel();
	buttonPane.add(closeButton);

	content.add(sp, BorderLayout.CENTER);
	content.add(buttonPane, BorderLayout.SOUTH);
}
 
Example 9
Source File: UserInterface.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
        Row r = new Row();
        JFrame testWindow = new JFrame();
        testWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        testWindow.setSize(900, 600);
        Container content = testWindow.getContentPane();
        content.setLayout(new BoxLayout(testWindow.getContentPane(), BoxLayout.Y_AXIS));
        content.setBackground(Theme.background.color);
        content.setForeground(Theme.foreground.color);
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
        content.add(createRowEditor(r));
//        testWindow.doLayout();
        testWindow.setVisible(true);
    }
 
Example 10
Source File: POptionPane.java    From PolyGlot with MIT License 5 votes vote down vote up
private static void setAllWhite(Container c) {
    Component[] comp = c.getComponents();

    c.setBackground(Color.white);
    for (Component curComp : comp) {
        curComp.setBackground(Color.white);
        setAllWhite((Container) curComp);
    }
}
 
Example 11
Source File: SplashScreen.java    From launcher with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private SplashScreen() throws IOException
{
	BufferedImage logo = ImageIO.read(SplashScreen.class.getResourceAsStream("runelite_transparent.png"));

	setTitle("RuneLite Launcher");

	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setUndecorated(true);
	setIconImage(logo);
	setLayout(null);
	Container pane = getContentPane();
	pane.setBackground(DARKER_GRAY_COLOR);

	Font font = new Font(Font.DIALOG, Font.PLAIN, 12);

	JLabel logoLabel = new JLabel(new ImageIcon(logo));
	pane.add(logoLabel);
	logoLabel.setBounds(0, 0, WIDTH, WIDTH);

	int y = WIDTH;

	pane.add(action);
	action.setForeground(Color.WHITE);
	action.setBounds(0, y, WIDTH, 16);
	action.setHorizontalAlignment(SwingConstants.CENTER);
	action.setFont(font);
	y += action.getHeight() + PAD;

	pane.add(progress);
	progress.setForeground(BRAND_ORANGE);
	progress.setBackground(BRAND_ORANGE.darker().darker());
	progress.setBorder(new EmptyBorder(0, 0, 0, 0));
	progress.setBounds(0, y, WIDTH, 14);
	progress.setFont(font);
	progress.setUI(new BasicProgressBarUI()
	{
		@Override
		protected Color getSelectionBackground()
		{
			return Color.BLACK;
		}

		@Override
		protected Color getSelectionForeground()
		{
			return Color.BLACK;
		}
	});
	y += 12 + PAD;

	pane.add(subAction);
	subAction.setForeground(Color.LIGHT_GRAY);
	subAction.setBounds(0, y, WIDTH, 16);
	subAction.setHorizontalAlignment(SwingConstants.CENTER);
	subAction.setFont(font);
	y += subAction.getHeight() + PAD;

	setSize(WIDTH, y);
	setLocationRelativeTo(null);

	timer = new Timer(100, this);
	timer.setRepeats(true);
	timer.start();

	setVisible(true);
}
 
Example 12
Source File: StudentSystemLoginFrame.java    From StudentSystem with Apache License 2.0 4 votes vote down vote up
public StudentSystemLoginFrame(){
	super("ѧ���ɼ�����ϵͳ��¼����");
	this.jf = this;
	this.setLayout(null);//����Ϊ�ղ��֡�
	this.setSize(400,300);//���ô�С��
	Container c = this.getContentPane();
	c.setBackground(Color.WHITE);//���ñ�����ɫ��
	username_Label = new JLabel("�û���:");	//����"�û���"��ǩ��
	username_Label.setBounds(100, 60, 50, 20);	//����"�û���"��ǩλ�á�
	c.add(username_Label);	//���"�û���"��ǩ��
	
	username_Text = new JTextField();	//����"�û���"�ı���
	username_Text.setBounds(160, 60, 120, 20);	//����"�û���"�ı���λ�á�
	username_Text.grabFocus();//��ù�ꡣ
	c.add(username_Text);	//���"�û���"�ı���
	
	password_Label = new JLabel("����:");	//����"����"��ǩ��
	password_Label.setBounds(100, 140, 50, 20);
	c.add(password_Label);	//���"����"��ǩ��
	
	password_Text = new JPasswordField();	//����"����"�ı���
	password_Text.setBounds(160, 140, 120, 20);	//����"����"�ı���λ�á�
	c.add(password_Text);	//���"����"�ı���
	 
	login_Button = new JButton("��¼");	//����"��¼"��ť��
	login_Button.setBounds(100, 210, 60, 20);	//����"��¼"��ťλ�á�
	//ע��"��¼"��ť�¼�������
	login_Button.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			String username = username_Text.getText().trim();
			String password = new String(password_Text.getPassword());
			if(username.equals("")){
				JOptionPane.showMessageDialog(jf, "�û�������Ϊ��","",JOptionPane.WARNING_MESSAGE);
				return ;
			}
			if(password.equals("")){
				JOptionPane.showMessageDialog(jf, "���벻��Ϊ��","",JOptionPane.WARNING_MESSAGE);
				return ;
			}
			//��¼ҵ����
			User user = new User();//�����û�����
			user.setUsername(username);
			user.setPassword(password);
			ManageHelper helper = new ManageHelper();//�������ݿ�ҵ�������
			if(helper.Login(user)){	//��½ҵ����
				if(helper.Check_IsLogin(user)){
					JOptionPane.showMessageDialog(jf, "�ظ���½��","",JOptionPane.WARNING_MESSAGE);
					return ;
				}else{
					JOptionPane.showMessageDialog(jf, "��½�ɹ���");
					jf.dispose();//�رյ�ǰ���ڡ�
					//�޸ĵ�½���
					user.setIsLogin(1);//�޸ij�Ϊ�Ѿ���½��
					helper.Update_IsLogin(user);
					//��������
					user.setPassword("");//��������
					StudentSystemMainFrame frame = new StudentSystemMainFrame(user);
					return ;
				}
			}else{
				JOptionPane.showMessageDialog(jf, "�û������������");
				 Reset();	//����
				return ;
			}
			
		}
	});
	c.add(login_Button);	//���"��¼"��ť ��
	
	
	register_Button = new JButton("ע��");	//����"ע��"��ť��
	register_Button.setBounds(250, 210, 60, 20);	//����"ע��"��ťλ�á�
	//ע��"ע��"��ť�¼�������
	register_Button.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			jf.dispose();	//��ǰ���ڹرա�
			StudentSystemRegisterFrame studentSystemRegisterFrame = new StudentSystemRegisterFrame();	//��ע�����		
			
		}
	});
	c.add(register_Button);	//���"ע��"��ť��
	
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	this.setResizable(false);	//���ô�С���ɸı䡣
	WindowUtil.setFrameCenter(this);//���ô��ھ��С�
	try {
		Image img = ImageIO.read(this.getClass().getResource("/2.png"));
		this.setIconImage(img);
		
	} catch (IOException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	
	this.setVisible(true);	//���ô���ɼ���
}
 
Example 13
Source File: SplashScreen.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private SplashScreen() throws IOException
{
	BufferedImage logo = ImageUtil.getResourceStreamFromClass(SplashScreen.class, "runelite_transparent.png");

	setTitle("RuneLite Launcher");

	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setUndecorated(true);
	setIconImage(logo);
	setLayout(null);
	Container pane = getContentPane();
	pane.setBackground(ColorScheme.DARKER_GRAY_COLOR);

	Font font = new Font(Font.DIALOG, Font.PLAIN, 12);

	JLabel logoLabel = new JLabel(new ImageIcon(logo));
	pane.add(logoLabel);
	logoLabel.setBounds(0, 0, WIDTH, WIDTH);

	int y = WIDTH;

	pane.add(action);
	action.setForeground(Color.WHITE);
	action.setBounds(0, y, WIDTH, 16);
	action.setHorizontalAlignment(SwingConstants.CENTER);
	action.setFont(font);
	y += action.getHeight() + PAD;

	pane.add(progress);
	progress.setForeground(ColorScheme.BRAND_ORANGE);
	progress.setBackground(ColorScheme.BRAND_ORANGE.darker().darker());
	progress.setBorder(new EmptyBorder(0, 0, 0, 0));
	progress.setBounds(0, y, WIDTH, 14);
	progress.setFont(font);
	progress.setUI(new BasicProgressBarUI()
	{
		@Override
		protected Color getSelectionBackground()
		{
			return Color.BLACK;
		}

		@Override
		protected Color getSelectionForeground()
		{
			return Color.BLACK;
		}
	});
	y += 12 + PAD;

	pane.add(subAction);
	subAction.setForeground(Color.LIGHT_GRAY);
	subAction.setBounds(0, y, WIDTH, 16);
	subAction.setHorizontalAlignment(SwingConstants.CENTER);
	subAction.setFont(font);
	y += subAction.getHeight() + PAD;

	setSize(WIDTH, y);
	setLocationRelativeTo(null);

	timer = new Timer(100, this);
	timer.setRepeats(true);
	timer.start();

	setVisible(true);
}
 
Example 14
Source File: ErrorLogFrame.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public ErrorLogFrame() {
    setTitle(translate("dialog.title"));
    setSize(700, 400);
    setBackground(Color.white);
    View.centerScreen(this);
    View.setWindowIcon(this);
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    Container cnt = getContentPane();
    cnt.setLayout(new BorderLayout());
    logView.setBackground(Color.white);
    logView.setLayout(new BorderLayout());
    cnt.setBackground(Color.white);

    logViewInner.setLayout(new BoxLayout(logViewInner, BoxLayout.Y_AXIS));
    logView.add(logViewInner, BorderLayout.NORTH);
    JPanel buttonsPanel = new JPanel(new FlowLayout());
    JButton clearButton = new JButton(translate("clear"));
    clearButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            clearLog();
        }
    });
    buttonsPanel.add(clearButton);

    expandIcon = View.getIcon("expand16");
    collapseIcon = View.getIcon("collapse16");
    cnt.add(buttonsPanel, BorderLayout.SOUTH);

    cnt.add(new JScrollPane(logView), BorderLayout.CENTER);
    handler = new Handler() {
        SimpleFormatter formatter = new SimpleFormatter();

        @Override
        public void publish(LogRecord record) {
            if (getLevel().intValue() <= record.getLevel().intValue()) {
                log(record.getLevel(), formatter.formatMessage(record), record.getThrown());
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };
    handler.setLevel(Level.WARNING);
}