Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,337 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,665 people online right now. Registration is fast and FREE... Join Now!




NetBeans Swing Form Background Color

 

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

Locke

28 Jun, 2008 - 01:38 PM
Post #1

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

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 online!Profile CardPM
+Quote Post


1lacca

RE: NetBeans Swing Form Background Color

28 Jun, 2008 - 02:33 PM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 31 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
+Quote Post

Locke

RE: NetBeans Swing Form Background Color

28 Jun, 2008 - 03:15 PM
Post #3

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

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 - 03:17 PM
User is online!Profile CardPM
+Quote Post

RoboAlex

RE: NetBeans Swing Form Background Color

28 Jun, 2008 - 06:19 PM
Post #4

New D.I.C Head
*

Joined: 26 Jun, 2008
Posts: 39



Thanked: 4 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
+Quote Post

Locke

RE: NetBeans Swing Form Background Color

29 Jun, 2008 - 04:51 PM
Post #5

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

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 online!Profile CardPM
+Quote Post

pbl

RE: NetBeans Swing Form Background Color

29 Jun, 2008 - 05:25 PM
Post #6

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,533



Thanked: 1124 times
Dream Kudos: 450
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 offlineProfile CardPM
+Quote Post

Locke

RE: NetBeans Swing Form Background Color

30 Jun, 2008 - 12:53 PM
Post #7

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
That's really weird.
User is online!Profile CardPM
+Quote Post

abgorn

RE: NetBeans Swing Form Background Color

1 Jul, 2008 - 01:55 AM
Post #8

sudo apt-get install brain
Group Icon

Joined: 5 Jun, 2008
Posts: 1,341



Thanked: 15 times
Dream Kudos: 50
My Contributions
When I use NetBeans it works, but not in the preview. It only shows when you run the file.
User is online!Profile CardPM
+Quote Post

Locke

RE: NetBeans Swing Form Background Color

1 Jul, 2008 - 09:27 AM
Post #9

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
...That's even weirder.
User is online!Profile CardPM
+Quote Post

1lacca

RE: NetBeans Swing Form Background Color

1 Jul, 2008 - 12:43 PM
Post #10

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 31 times
My Contributions
Why would it be weirder, the preview sucks, period biggrin.gif
User is offlineProfile CardPM
+Quote Post

Locke

RE: NetBeans Swing Form Background Color

2 Jul, 2008 - 08:41 PM
Post #11

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

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 online!Profile CardPM
+Quote Post

RoboAlex

RE: NetBeans Swing Form Background Color

6 Jul, 2008 - 07:41 AM
Post #12

New D.I.C Head
*

Joined: 26 Jun, 2008
Posts: 39



Thanked: 4 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
+Quote Post

Locke

RE: NetBeans Swing Form Background Color

6 Jul, 2008 - 10:27 AM
Post #13

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
...THAT SUCKS.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 05:10PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month