Welcome to Dream.In.Code
Click Here
Getting Java Help is Easy!

Join 117,527 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 1,973 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



NetBeans Swing Form Background Color

2 Pages V  1 2 >  
Reply to this topicStart new topic

NetBeans Swing Form Background Color, Can't seem to get it to change

Locke37
post 28 Jun, 2008 - 02:38 PM
Post #1


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 549



Thanked 16 times

Dream Kudos: 300
My Contributions


Well, I am using NetBeans, using the Swing GUI Creator. The problem is, I have changed the background color property to the standard black [0, 0, 0] color. The problem is, at runtime, the color isn't actually changed, it stays the default kinda greyish color.

Any ideas?
User is offlineProfile CardPM

Go to the top of the page


1lacca
post 28 Jun, 2008 - 03:33 PM
Post #2


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,804



Thanked 11 times
My Contributions


Could you post the generated code?
Or even better: check it yourself. If you have a look at it, you'll see what the IDE is trying to do, and if you've set the background color of the right component.
User is offlineProfile CardPM

Go to the top of the page

Locke37
post 28 Jun, 2008 - 04:15 PM
Post #3


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 549



Thanked 16 times

Dream Kudos: 300
My Contributions


I set the background of the form, not just 1 component. I don't have another form at the moment, and only 1 button on my current form, so it's pretty difficult (I believe) for NetBeans to screw this up.

java
private void initComponents() 
{
jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Login");
setAlwaysOnTop(true);
setBackground(new java.awt.Color(0, 0, 0));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setResizable(false);

jButton1.setText("Login");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(142, 142, 142)
.addComponent(jButton1)
.addContainerGap(149, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(167, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(41, 41, 41))
);

jButton1.getAccessibleContext().setAccessibleName(null);

pack();
}// </editor-fold>


The setBackground(new java.awt.Color(0, 0, 0)) command is correct, since it's just doing this to the form...

EDIT: ARGH, I hate the way NetBeans generates code. (I just switched the brace locations.)

This post has been edited by Locke37: 28 Jun, 2008 - 04:17 PM
User is offlineProfile CardPM

Go to the top of the page

RoboAlex
post 28 Jun, 2008 - 07:19 PM
Post #4


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 39



Thanked 3 times
My Contributions


I'm assuming that this class extends JFrame, so what I think you need to do is:
getContentPane().setBackground(Color.BLACK);
User is offlineProfile CardPM

Go to the top of the page

Locke37
post 29 Jun, 2008 - 05:51 PM
Post #5


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 549



Thanked 16 times

Dream Kudos: 300
My Contributions


Well that's odd...I don't know quite why that worked. Since you would THINK that NetBeans would be smart enough to do that on it's own since I set the property on the form the same as I did in the code.

java
private LoginForm()
{
initComponents();
getContentPane().setBackground(java.awt.Color.black);
}


I still don't know why it doesnt do that automatically...But thanks all the same! icon_up.gif
User is offlineProfile CardPM

Go to the top of the page

pbl
post 29 Jun, 2008 - 06:25 PM
Post #6


D.I.C Lover

Group Icon
Joined: 6 Mar, 2008
Posts: 2,278



Thanked 132 times

Dream Kudos: 75
My Contributions


I gess it has nothing to do with NetBeans default colors
It has to do with default Java bacground colors around Windows default dark gray
User is online!Profile CardPM

Go to the top of the page

Locke37
post 30 Jun, 2008 - 01:53 PM
Post #7


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 549



Thanked 16 times

Dream Kudos: 300
My Contributions


That's really weird.
User is offlineProfile CardPM

Go to the top of the page

abgorn
post 1 Jul, 2008 - 02:55 AM
Post #8


D.I.C Regular

***
Joined: 5 Jun, 2008
Posts: 484



Thanked 2 times
My Contributions


When I use NetBeans it works, but not in the preview. It only shows when you run the file.
User is offlineProfile CardPM

Go to the top of the page

Locke37
post 1 Jul, 2008 - 10:27 AM
Post #9


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 549



Thanked 16 times

Dream Kudos: 300
My Contributions


...That's even weirder.
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 1 Jul, 2008 - 01:43 PM
Post #10


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,804



Thanked 11 times
My Contributions


Why would it be weirder, the preview sucks, period biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Locke37
post 2 Jul, 2008 - 09:41 PM
Post #11


I'm not a thief...I prefer the term TREASURE HUNTER!

Group Icon
Joined: 20 Mar, 2008
Posts: 549



Thanked 16 times

Dream Kudos: 300
My Contributions


Well, I don't know why NetBeans isn't smart enough to be like VB, and ACTUALLY change the color of the window instead of making me do it manually EVERY time.
User is offlineProfile CardPM

Go to the top of the page

RoboAlex
post 6 Jul, 2008 - 08:41 AM
Post #12


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 39



Thanked 3 times
My Contributions


I'm not sure how you are doing it in netbeans, but if you are asking it to change the background color of the JFrame, then it is doing exactly what it should. The JFrame has a background color, but the entire contents of a JFrame are covered by the content pane, so you need to change to color of the content pane, not the JFrame. Otherwise the content pane simply covers the JFrame and there is no change.
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 03:48PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month