School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,154 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,961 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 Rate Topic: -----

#1 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 28 June 2008 - 01:38 PM

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?
Was This Post Helpful? 0
  • +
  • -


#2 1lacca  Icon User is offline

  • code.rascal
  • Icon
  • Group: Alumni
  • Posts: 3,822
  • Joined: 11-August 05


Dream Kudos: 0

Posted 28 June 2008 - 02:33 PM

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.
Was This Post Helpful? 0
  • +
  • -

#3 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 28 June 2008 - 03:15 PM

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.

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 June 2008 - 03:17 PM

Was This Post Helpful? 0
  • +
  • -

#4 RoboAlex  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 26-June 08


Dream Kudos: 0

Posted 28 June 2008 - 06:19 PM

I'm assuming that this class extends JFrame, so what I think you need to do is:
getContentPane().setBackground(Color.BLACK);
Was This Post Helpful? 1

#5 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 29 June 2008 - 04:51 PM

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.

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! :^:
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • Java Lover
  • Icon
  • Group: Mentors
  • Posts: 11,168
  • Joined: 06-March 08


Dream Kudos: 475

Posted 29 June 2008 - 05:25 PM

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
Was This Post Helpful? 0
  • +
  • -

#7 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 30 June 2008 - 12:53 PM

That's really weird.
Was This Post Helpful? 0
  • +
  • -

#8 abgorn  Icon User is offline

  • sudo apt-get install brain
  • Icon
  • View blog
  • Group: Contributors
  • Posts: 1,360
  • Joined: 05-June 08


Dream Kudos: 50

Posted 01 July 2008 - 01:55 AM

When I use NetBeans it works, but not in the preview. It only shows when you run the file.
Was This Post Helpful? 0
  • +
  • -

#9 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 01 July 2008 - 09:27 AM

...That's even weirder.
Was This Post Helpful? 0
  • +
  • -

#10 1lacca  Icon User is offline

  • code.rascal
  • Icon
  • Group: Alumni
  • Posts: 3,822
  • Joined: 11-August 05


Dream Kudos: 0

Posted 01 July 2008 - 12:43 PM

Why would it be weirder, the preview sucks, period :D
Was This Post Helpful? 0
  • +
  • -

#11 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 02 July 2008 - 08:41 PM

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.
Was This Post Helpful? 0
  • +
  • -

#12 RoboAlex  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 26-June 08


Dream Kudos: 0

Posted 06 July 2008 - 07:41 AM

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.
Was This Post Helpful? 0
  • +
  • -

#13 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 06 July 2008 - 10:27 AM

...THAT SUCKS.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month