Board index » jbuilder » JButton Color

JButton Color


2007-06-29 04:46:13 AM
jbuilder12
I am using JBuilder2006 and am trying to change the color of the JButton and
it doesn't work for some reason.
JButton jb = new JButton();
jb.setOpaque(false);
jb.setBackground(Color.blue);
Is there anything else I should do? I am using WindowsXp.
Regards
Arun
 
 

Re:JButton Color

Try setting Opaque to true.
Arth
"Arun Bommannavar" < XXXX@XXXXX.COM >wrote in message
Quote
I am using JBuilder2006 and am trying to change the color of the JButton
and it doesn't work for some reason.

JButton jb = new JButton();
jb.setOpaque(false);
jb.setBackground(Color.blue);

Is there anything else I should do? I am using WindowsXp.

Regards
Arun

 

Re:JButton Color

If you are new to Java Swing (GUI) development have a look at Sun's Java
Swing Tutorial.
java.sun.com/docs/books/tutorial/uiswing/
 

{smallsort}

Re:JButton Color

Arthur,
I have tried with both settings for opaque. Neither settings give me blue
buttons.
Here is the code that runs just fine if compiled outside JBuilder. Same
thing doesn't work for me when I compile and run inside JBuilder 2006 IDE.
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ButtonTest extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
public ButtonTest() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new Dimension(400, 300));
setTitle("Frame Title");
JPanel jp = new JPanel();
JButton jb = new JButton();
jb.setBackground(Color.blue);
jp.setLayout(borderLayout2);
contentPane.add(jp, java.awt.BorderLayout.CENTER);
jp.add(jb, java.awt.BorderLayout.CENTER);
}
public static void main(String[] args) {
ButtonTest bt = new ButtonTest();
bt.setVisible(true);
}
}
"Arthur Ore" < XXXX@XXXXX.COM >wrote in message
Quote
Try setting Opaque to true.

Arth

"Arun Bommannavar" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>I am using JBuilder2006 and am trying to change the color of the JButton
>and it doesn't work for some reason.
>
>JButton jb = new JButton();
>jb.setOpaque(false);
>jb.setBackground(Color.blue);
>
>Is there anything else I should do? I am using WindowsXp.
>
>Regards
>Arun
>


 

Re:JButton Color

I use JB2006-Ent and it displays blue in both design mode and when I run it.
Have you changed the JDK that it's running under? I'm using JDK 1.5
The other thing that might help is to try starting JBuilder using
C:\Borland\JBuilder2006\bin\JBuilder.exe -verbose>mylog.txt
(make sure you change the directories to suit your install.)
Do whatever you would do to test that it displays blue. Close JBuilder and
have a look in mylog.txt to see if there are any errors.
If there are, you could post them here and someone might know what is
causing them.
Arth
"Arun Bommannavar" < XXXX@XXXXX.COM >wrote in message
Quote
Arthur,

I have tried with both settings for opaque. Neither settings give me blue
buttons.

Here is the code that runs just fine if compiled outside JBuilder. Same
thing doesn't work for me when I compile and run inside JBuilder 2006 IDE.


 

Re:JButton Color

I think this might be a bug. I created your ButtonTest class in the project
I'm playing with and forgot to delete it.
When I accidentally clicked back on your class, the button had turned grey
in the designer, and the background parameter showed LightGray.
However, in the source code the background colour was still set to blue.
When I ran it it displayed blue. Toggling between source and design mode
seemed to fix the problem. As did re-setting the background colour through
the designer.
Arth
 

Re:JButton Color

Arthur Ore wrote:
Quote
I think this might be a bug. I created your ButtonTest class in the project
I'm playing with and forgot to delete it.

When I accidentally clicked back on your class, the button had turned grey
in the designer, and the background parameter showed LightGray.

However, in the source code the background colour was still set to blue.
When I ran it it displayed blue. Toggling between source and design mode
seemed to fix the problem. As did re-setting the background colour through
the designer.
On OS X, setting the background color to Color.BLUE does not
produce a blue button. Setting opaque to true only produces
a blue rectangle around the lozenge-shaped OS X style button.
This is probably not what the original poster had in mind.
My thinking on this is that one may have to look into a
custom ButtonUI class ... but that's just a hunch.
--
Paul Furbacher (TeamB)
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:JButton Color

Confusion and interesting at the same time.
There were no obvious errors pertaining to my program, however, the log file
generated in the process of opening JBuilder,running my program and closing
it, is of 50KB size. The top line is as follows:
*****
C:\Borland\JBuilder2006\bin>JBuilder.exe -verbose>mylog.txt
*** Ignoring duplicate OpenTool
com.borland.jbuilder.optimize.IntroOptimizeitProfiler
javax.xml.transform.TransformerException: java.io.FileNotFoundException:
file:\C:\Documents%20and%20Settings\abomm\.jbuilder2006\workspaces\workspace1.workspace
(The filename, directory name, or volume label syntax is incorrect)
*********
It surprised me because there *is* the file in right place and it somehow
isn't seeing it. No hints about the error that I am looking for but it is
screaming about something else, which again, I have no clue about.
"Arthur Ore" < XXXX@XXXXX.COM >wrote in message
Quote
I use JB2006-Ent and it displays blue in both design mode and when I run
it.
Have you changed the JDK that it's running under? I'm using JDK 1.5

The other thing that might help is to try starting JBuilder using

C:\Borland\JBuilder2006\bin\JBuilder.exe -verbose>mylog.txt
(make sure you change the directories to suit your install.)

Do whatever you would do to test that it displays blue. Close JBuilder and
have a look in mylog.txt to see if there are any errors.

If there are, you could post them here and someone might know what is
causing them.

Arth


"Arun Bommannavar" < XXXX@XXXXX.COM >wrote in message
news:46851f3c$ XXXX@XXXXX.COM ...
>Arthur,
>
>I have tried with both settings for opaque. Neither settings give me blue
>buttons.
>
>Here is the code that runs just fine if compiled outside JBuilder. Same
>thing doesn't work for me when I compile and run inside JBuilder 2006
>IDE.
>
>






 

Re:JButton Color

Paul,
You are right. Setting Opaque to true only produces a thin blue rectangle
around the edge of the button but the button itself is LightGray.
I am using JBuilder2006 Developer version. I remember the same symptoms were
present in JBuilder X ent version.
"Paul Furbacher [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Arthur Ore wrote:
>I think this might be a bug. I created your ButtonTest class in the
>project I'm playing with and forgot to delete it.
>
>When I accidentally clicked back on your class, the button had turned
>grey in the designer, and the background parameter showed LightGray.
>
>However, in the source code the background colour was still set to blue.
>When I ran it it displayed blue. Toggling between source and design mode
>seemed to fix the problem. As did re-setting the background colour
>through the designer.

On OS X, setting the background color to Color.BLUE does not
produce a blue button. Setting opaque to true only produces
a blue rectangle around the lozenge-shaped OS X style button.
This is probably not what the original poster had in mind.

My thinking on this is that one may have to look into a
custom ButtonUI class ... but that's just a hunch.


--


Paul Furbacher (TeamB)

Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.