java.awt.Container#setBackground ( )源码实例Demo

下面列出了java.awt.Container#setBackground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlatLaf   文件: FlatRootPaneUI.java
@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 );
	}
}
 
源代码2 项目: dragonwell8_jdk   文件: SlowPanelIteration.java
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;
}
 
源代码3 项目: TencentKona-8   文件: SlowPanelIteration.java
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;
}
 
源代码4 项目: CPE552-Java   文件: ChatWindow.java
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); 
}
 
源代码5 项目: CPE552-Java   文件: Win2.java
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); 
}
 
源代码6 项目: openjdk-jdk8u   文件: SlowPanelIteration.java
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;
}
 
源代码7 项目: jdk8u_jdk   文件: SlowPanelIteration.java
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;
}
 
源代码8 项目: stendhal   文件: CreditsDialog.java
/**
 * 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);
}
 
源代码9 项目: jace   文件: UserInterface.java
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);
    }
 
源代码10 项目: PolyGlot   文件: POptionPane.java
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);
    }
}
 
源代码11 项目: launcher   文件: SplashScreen.java
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);
}
 
源代码12 项目: StudentSystem   文件: StudentSystemLoginFrame.java
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);	//���ô���ɼ���
}
 
源代码13 项目: runelite   文件: SplashScreen.java
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);
}
 
源代码14 项目: jpexs-decompiler   文件: ErrorLogFrame.java
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);
}