4 Replies - 11410 Views - Last Post: 29 September 2009 - 09:30 PM Rate Topic: -----

#1 javafreak  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 97
  • Joined: 21-September 09

how to change JFrame background color

Posted 29 September 2009 - 02:23 AM

setBackground(Color.GREEN); //its not working


the jpanel calling this jframe
{
	
			
	SEL page=new SEL();
		page.setBackground(Color.GREEN);
		page.setSize(700,500);
		page.setVisible(true);
		page.getContentPane();
		jFrame.setVisible(false);
		jFrame.dispose();
		}




 
	import java.awt.*;
	import java.awt.event.*;
	import javax.swing.*;
	import javax.swing.event.*;

	public class SEL extends JFrame {
		private JButton jcomp1;
		private JButton jcomp2;
   	 private JButton jcomp3;
   	 private JButton jcomp5;
   	 private JLabel jcomp6;

// action listeners
	ActionListener new_rec = new new_rec();
	ActionListener view_rec = new view_rec();
	ActionListener del_rec = new del_rec();
	ActionListener exitc = new exitc();
	
	public SEL() {
		//construct components

super ( "Selection form make choice" );
setBackground(Color.GREEN);   //its not working
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
	 jcomp1 = new JButton ("insert records");
		jcomp2 = new JButton ("preview records");
		jcomp3 = new JButton ("delete records");
		jcomp5 = new JButton ("EXIT");
		jcomp6 = new JLabel ("MANGEMENT SYSTEM");

jcomp2.setForeground(Color.RED);
	//attach buttons with actionlisteners
	jcomp1.addActionListener(new_rec);
	jcomp2.addActionListener(view_rec);
	jcomp3.addActionListener(del_rec);
	jcomp5.addActionListener(exitc);
			

	//adjust size and set layout
	
		setPreferredSize (new Dimension (611, 523));
		setLayout (null);

		//add components
		add (jcomp1);
		add (jcomp2);
		add (jcomp3);
		add (jcomp5);
		add (jcomp6);

		//set component bounds (only needed by Absolute Positioning)
		jcomp1.setBounds (80, 165, 175, 30);
		jcomp2.setBounds (300, 165, 185, 30);
		jcomp3.setBounds (10, 290, 100, 25);
 
		jcomp5.setBounds (245, 290, 100, 25);
		jcomp6.setBounds (225, 55, 330, 40);
	}


class new_rec implements ActionListener {
public void actionPerformed(ActionEvent event){
 AddRec pagee=new AddRec();
		pagee.setSize(700,500);
			pagee.setVisible(true);
 	
}
}

class del_rec implements ActionListener {
public void actionPerformed(ActionEvent event){
 DelRec pageee=new DelRec();
		pageee.setSize(700,500);
			pageee.setVisible(true);
		
 	
}
}

class view_rec implements ActionListener {
public void actionPerformed(ActionEvent event){
DisplayQueryResults pageeee=new DisplayQueryResults();
		pageeee.setSize(700,500);
			pageeee.setVisible(true);
 	
}
}


class exitc implements ActionListener {
public void actionPerformed(ActionEvent event){
	System.exit(0);
}
}

	public static void main (String[] args) {
		JFrame frame = new JFrame ("SELE");
		frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add (new SEL());
		frame.pack();
		frame.setVisible (true);
	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: how to change JFrame background color

#2 greenDevil  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 14-September 09

Re: how to change JFrame background color

Posted 29 September 2009 - 02:33 AM

in main method
frame.setBackground(Color.pink);


Was This Post Helpful? 0
  • +
  • -

#3 javafreak  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 97
  • Joined: 21-September 09

Re: how to change JFrame background color

Posted 29 September 2009 - 04:10 AM

i done with it used getContentPane().setBackground(Color.GREEN);
Was This Post Helpful? 1

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: how to change JFrame background color

Posted 29 September 2009 - 03:38 PM

Your setBackground() should work
If it doesn't it is because your JFrame is fuull of components that hide its back
Was This Post Helpful? 0
  • +
  • -

#5 LynnL  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 109
  • Joined: 13-April 09

Re: how to change JFrame background color

Posted 29 September 2009 - 09:30 PM

View Postpbl, on 29 Sep, 2009 - 02:38 PM, said:

Your setBackground() should work
If it doesn't it is because your JFrame is fuull of components that hide its back

You'll have to make your JPanel setOpaque(false); to see the background color behind
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1