1 Replies - 322 Views - Last Post: 27 June 2012 - 05:47 PM Rate Topic: -----

#1 Ploug  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-June 12

Cant get a background Color on my JFrame with setBackground.

Posted 27 June 2012 - 05:17 PM

Hey, so i want to make a GUI for a math solver i am making. But i want the background to be white. I have been looking alot at other topics here, and they say to use setBackground(new Color(256,256,256)), which is also what i tried before i got on here. Also tried setBackground(color.WHITE) or something like that.

Here is my code
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.Color;






public class GUI extends JFrame
{
	
	private JTextField i;
	private JTextField ii;
	private JTextField iii;
	private JButton løs;
	
	public GUI()
	{
	
		setTitle("Detiminant Løser");
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(600,650);
		setResizable(false);
		setLayout(null);
		setBackground(new Color(255,255,255));
		
		løs = new JButton("løs");
		løs.setSize(50,25);
		løs.setLocation(50,50);
		add(løs);
		i = new JTextField("Første Ligning",30);
		add(i);
		ii = new JTextField("Anden Ligning",30);
		add(ii);
		iii = new JTextField("Tredje Ligning", 30);
		add(iii);
		
		 
		
	}

	

}


And the main class
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.UIManager;


public class startup {

	
	public static void main(String[] args) 
	{

		try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) {}
		GUI f = new GUI();
		
		
		
		
		
		

	}

}



I also added a picture of how it looks.

Is This A Good Question/Topic? 0
  • +

Replies To: Cant get a background Color on my JFrame with setBackground.

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,214
  • Joined: 20-September 08

Re: Cant get a background Color on my JFrame with setBackground.

Posted 27 June 2012 - 05:47 PM

getContentPane().setBackground(Color.white);


is what you need
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1