Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
setting bg in jDialog
miguel lisboa
Ranch Hand
Posts: 1282
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
how can i set background color in a jDialog?
my code:
JOptionPane optionPane = new JOptionPane(txt, JOptionPane.WARNING_MESSAGE); JDialog dialog = optionPane.createDialog(new JFrame(), titulo); optionPane.setBackground(Color.white); // dialog.getContentPane().setBackground(Color.white); // dialog.setBackground(Color.white); // dialog.getParent().setBackground(Color.white); dialog.setVisible(true);
nothing of this works...
TiA
java amateur
Kaydell Leavitt
Ranch Hand
Posts: 694
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm not sure that I understand. The default background color is white isn't it?
I got the following to work in a JFrame:
setBackground(new Color(1.0f,1.0f,0.8f));
If something like this doesn't work for you, the only thing that I can think of that I might have done differently is to disable the layout managers:
// --- Turn off layout managers. They're more trouble than they're worth. --- // setLayout(null); getContentPane().setLayout(null);
[ May 19, 2007: Message edited by: Kaydell Leavitt ]
[ May 19, 2007: Message edited by: Kaydell Leavitt ]
miguel lisboa
Ranch Hand
Posts: 1282
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The default background color is white isn't it?
no
and its not a frame, but a jDialog
(layout is automatic)
java amateur
Craig Wood
Ranch Hand
Posts: 1535
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.awt.*; import javax.swing.*; public class SetBackgroundTest { static JPanel message; public static void main(String[] args) { message = new JPanel(); message.setBackground(Color.pink); message.setPreferredSize(new Dimension(100,50)); JOptionPane pane = new JOptionPane(message, JOptionPane.WARNING_MESSAGE); pane.setBackground(Color.red); changeBackgroundFor(pane, Color.red); JDialog dialog = pane.createDialog(null, "dialog"); dialog.pack(); dialog.setLocation(200,200); dialog.setVisible(true); } private static void changeBackgroundFor(Container parent, Color color) { Component[] c = parent.getComponents(); for(int j = 0; j < c.length; j++) { System.out.println("c["+j+"] = " + c[j].getClass().getName()); if(c[j] instanceof JPanel && c[j] != message) { ((JPanel)c[j]).setBackground(color); } if(c[j] instanceof Container) { changeBackgroundFor((Container)c[j], color); } } } }
miguel lisboa
Ranch Hand
Posts: 1282
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks for your help, Craig
while i'm still studying your code, i added
if(c[j] instanceof JLabel) { JLabel label = (JLabel)c[j]; label.setText("N�mero mal formatado."); }
java amateur
Kaydell Leavitt
Ranch Hand
Posts: 694
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Are there some key points that you can tell me so that I can get layout managers to work for me?
Kaydell
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
jTable background? problem
How to change the background color of a Dialog?
JScrollPane
JOptionPane
How to specify size for a JOptionpane showOptionDialog
More...