Problem with JDialog box

Hi Guys,

I have a problem with the JDialog box. The close button (Cross mark of the box) is not displayed when I was trying to use my custom LookAndFeel and Custom theme. I am pasting the code sample here.

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.Icon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.LookAndFeel;

import javax.swing.SwingUtilities;

import javax.swing.UIDefaults;

import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;

import com.jgoodies.looks.plastic.PlasticTheme;

import com.medplexus.looks.plastic.theme.SkyGreen;

public class TestTheDialog implements ActionListener {

JFrame mainFrame = null;

JButton myButton = null;

public TestTheDialog() {

mainFrame = new JFrame("TestTheDialog Tester");

mainFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {System.exit(0);}

});

try{

MyLookAndFeel.setCurrentTheme(new CustomLaF());

UIManager.setLookAndFeel(new MyLookAndFeel());

SwingUtilities.updateComponentTreeUI(mainFrame);

CustomDialog cd = new CustomDialog();

cd.setDefaultLookAndFeelDecorated(true);

}

catch(Exception e){

}

myButton = new JButton("Test the dialog!");

myButton.addActionListener(this);

mainFrame.setLocationRelativeTo(null);

mainFrame.getContentPane().add(myButton);

mainFrame.setSize(200, 150);

//mainFrame.pack();

mainFrame.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(myButton == e.getSource()) {

System.err.println("Opening dialog.");

CustomDialog myDialog = new CustomDialog(mainFrame, true, "Do you like Java?");

System.err.println("After opening dialog.");

if(myDialog.getAnswer()) {

System.err.println("The answer stored in CustomDialog is 'true' (i.e. user clicked yes button.)");

}

else {

System.err.println("The answer stored in CustomDialog is 'false' (i.e. user clicked no button.)");

}

}

}

static class CustomLaF extends PlasticTheme {

protected ColorUIResource getPrimary1() {

return new ColorUIResource(255,128,0);

}

public ColorUIResource getPrimary2() {

return (new ColorUIResource(Color.white));

}

public ColorUIResource getPrimary3() {

return (new ColorUIResource(255,128,0));

}

public ColorUIResource getPrimaryControl() {

return new ColorUIResource(Color.GREEN);

}

protected ColorUIResource getSecondary1() {

return new ColorUIResource(Color.CYAN);

}

protected ColorUIResource getSecondary2() {

return (new ColorUIResource(Color.gray));

}

protected ColorUIResource getSecondary3() {

return (new ColorUIResource(235,235,235));

}

protected ColorUIResource getBlack() {

return BLACK;

}

protected ColorUIResource getWhite() {

return WHITE;

}

private Object getIconResource(String s) {

return LookAndFeel.makeIcon(getClass(), s);

}

private Icon getHastenedIcon(String s, UIDefaults uidefaults) {

Object obj = getIconResource(s);

return (Icon) ((javax.swing.UIDefaults.LazyValue) obj).createValue(uidefaults);

}

}

static class MyLookAndFeel extends Plastic3DLookAndFeel {

protected void initClassDefaults(UIDefaults table) {

super.initClassDefaults(table);

}

protected void initComponentDefaults(UIDefaults table) {

super.initComponentDefaults(table);

Object[] defaults = {

"MenuItem.foreground",new ColorUIResource(Color.white),

"MenuItem.background",new ColorUIResource(Color.gray),

"MenuItem.selectionForeground",new ColorUIResource(Color.gray),

"MenuItem.selectionBackground",new ColorUIResource(Color.white),

"Menu.selectionForeground", new ColorUIResource(Color.white),

"Menu.selectionBackground", new ColorUIResource(Color.gray),

"MenuBar.background", new ColorUIResource(235,235,235),

"Menu.background", new ColorUIResource(235,235,235),

"Desktop.background",new ColorUIResource(235,235,235),

"Button.select",new ColorUIResource(255,128,0),

"Button.focus",new ColorUIResource(255,128,0),

"TableHeader.background", new ColorUIResource(255,128,0),

"TableHeader.foreground", new ColorUIResource(Color.white),

"ScrollBar.background", new ColorUIResource(235,235,235),

"OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),

"OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),

"OptionPane.questionDialog.titlePane.background", new ColorUIResource(255,128,0),

"InternalFrame.borderColor", new ColorUIResource(Color.gray),

"InternalFrame.activeTitleForeground", new ColorUIResource(Color.white),

"InternalFrame.activeTitleBackground", new ColorUIResource(Color.gray),

"InternalFrame.borderColor", new ColorUIResource(Color.white),

"Table.selectionBackground",new ColorUIResource(255,128,0)

};

table.putDefaults(defaults);

}

}

public static void main(String argv[]) {

TestTheDialog tester = new TestTheDialog();

}

}

--

package CustomThemes;

import javax.swing.JDialog;

import java.awt.event.ActionListener;

import javax.swing.JPanel;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JButton;

import java.awt.event.ActionEvent;

public class CustomDialog extends JDialog implements ActionListener {

private JPanel myPanel = null;

private JButton yesButton = null;

private JButton noButton = null;

private boolean answer = false;

public boolean getAnswer() { return answer; }

public CustomDialog(){

}

public CustomDialog(JFrame frame, boolean modal, String myMessage) {

super(frame, modal);

setTitle("Guess?");

myPanel = new JPanel();

getContentPane().add(myPanel);

myPanel.add(new JLabel(myMessage));

yesButton = new JButton("Yes");

yesButton.addActionListener(this);

myPanel.add(yesButton);

noButton = new JButton("No");

noButton.addActionListener(this);

myPanel.add(noButton);

setDefaultCloseOperation(EXIT_ON_CLOSE);

pack();

setLocationRelativeTo(frame);

setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(yesButton == e.getSource()) {

System.err.println("User chose yes.");

answer = true;

setVisible(false);

}

else if(noButton == e.getSource()) {

System.err.println("User chose no.");

answer = false;

setVisible(false);

}

}

}

Thanks and Regards

Kumar.

[7177 byte] By [hotguya] at [2007-10-3 8:18:57]
# 1
Use code tags. I am not going to even look at your code till then.
zadoka at 2007-7-15 3:24:24 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi All,

I am using the JGoodies Look and feel (looks2.0.1.jar). I wrote my own custom LookAndFeel and Theme , but the problem with this is the JDialog/JOptionPane dialog boxes are displayed with out the close button (cross button on the titlebar).

I am pasting the code here.

import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.Icon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.LookAndFeel;

import javax.swing.SwingUtilities;

import javax.swing.UIDefaults;

import javax.swing.UIManager;

import javax.swing.plaf.ColorUIResource;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;

import com.jgoodies.looks.plastic.PlasticTheme;

import com.medplexus.looks.plastic.theme.SkyGreen;

public class TestTheDialog implements ActionListener {

JFrame mainFrame = null;

JButton myButton = null;

public TestTheDialog() {

mainFrame = new JFrame("TestTheDialog Tester");

mainFrame.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {System.exit(0);}

});

try{

MyLookAndFeel.setCurrentTheme(new CustomLaF());

UIManager.setLookAndFeel(new MyLookAndFeel());

//Plastic3DLookAndFeel.setCurrentTheme(new SkyGreen());

//UIManager.setLookAndFeel(new Plastic3DLookAndFeel());

SwingUtilities.updateComponentTreeUI(mainFrame);

CustomDialog cd = new CustomDialog();

cd.setDefaultLookAndFeelDecorated(true);

}

catch(Exception e){

}

myButton = new JButton("Test the dialog!");

myButton.addActionListener(this);

mainFrame.setLocationRelativeTo(null);

mainFrame.getContentPane().add(myButton);

mainFrame.setSize(200, 150);

//mainFrame.pack();

mainFrame.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(myButton == e.getSource()) {

System.err.println("Opening dialog.");

CustomDialog myDialog = new CustomDialog(mainFrame, true, "Do you like Java?");

System.err.println("After opening dialog.");

if(myDialog.getAnswer()) {

System.err.println("The answer stored in CustomDialog is 'true' (i.e. user clicked yes button.)");

}

else {

System.err.println("The answer stored in CustomDialog is 'false' (i.e. user clicked no button.)");

}

}

}

static class CustomLaF extends PlasticTheme {

protected ColorUIResource getPrimary1() {

return new ColorUIResource(255,128,0);

}

public ColorUIResource getPrimary2() {

return (new ColorUIResource(Color.white));

}

public ColorUIResource getPrimary3() {

return (new ColorUIResource(255,128,0));

}

public ColorUIResource getPrimaryControl() {

return new ColorUIResource(Color.GREEN);

}

protected ColorUIResource getSecondary1() {

return new ColorUIResource(Color.CYAN);

}

protected ColorUIResource getSecondary2() {

return (new ColorUIResource(Color.gray));

}

protected ColorUIResource getSecondary3() {

return (new ColorUIResource(235,235,235));

}

protected ColorUIResource getBlack() {

return BLACK;

}

protected ColorUIResource getWhite() {

return WHITE;

}

private Object getIconResource(String s) {

return LookAndFeel.makeIcon(getClass(), s);

}

private Icon getHastenedIcon(String s, UIDefaults uidefaults) {

Object obj = getIconResource(s);

return (Icon) ((javax.swing.UIDefaults.LazyValue) obj).createValue(uidefaults);

}

}

static class MyLookAndFeel extends Plastic3DLookAndFeel {

protected void initClassDefaults(UIDefaults table) {

super.initClassDefaults(table);

}

protected void initComponentDefaults(UIDefaults table) {

super.initComponentDefaults(table);

Object[] defaults = {

"MenuItem.foreground",new ColorUIResource(Color.white),

"MenuItem.background",new ColorUIResource(Color.gray),

"MenuItem.selectionForeground",new ColorUIResource(Color.gray),

"MenuItem.selectionBackground",new ColorUIResource(Color.white),

"Menu.selectionForeground", new ColorUIResource(Color.white),

"Menu.selectionBackground", new ColorUIResource(Color.gray),

"MenuBar.background", new ColorUIResource(235,235,235),

"Menu.background", new ColorUIResource(235,235,235),

"Desktop.background",new ColorUIResource(235,235,235),

"Button.select",new ColorUIResource(255,128,0),

"Button.focus",new ColorUIResource(255,128,0),

"TableHeader.background", new ColorUIResource(255,128,0),

"TableHeader.foreground", new ColorUIResource(Color.white),

"ScrollBar.background", new ColorUIResource(235,235,235),

"OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),

"OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),

"OptionPane.questionDialog.titlePane.background", new ColorUIResource(255,128,0),

"InternalFrame.borderColor", new ColorUIResource(Color.gray),

"InternalFrame.activeTitleForeground", new ColorUIResource(Color.white),

"InternalFrame.activeTitleBackground", new ColorUIResource(Color.gray),

"InternalFrame.borderColor", new ColorUIResource(Color.white),

"Table.selectionBackground",new ColorUIResource(255,128,0)

};

table.putDefaults(defaults);

}

}

public static void main(String argv[]) {

TestTheDialog tester = new TestTheDialog();

}

}

-

import javax.swing.JDialog;

import java.awt.event.ActionListener;

import javax.swing.JPanel;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JButton;

import java.awt.event.ActionEvent;

public class CustomDialog extends JDialog implements ActionListener {

private JPanel myPanel = null;

private JButton yesButton = null;

private JButton noButton = null;

private boolean answer = false;

public boolean getAnswer() { return answer; }

public CustomDialog(){

}

public CustomDialog(JFrame frame, boolean modal, String myMessage) {

super(frame, modal);

setTitle("Guess?");

myPanel = new JPanel();

getContentPane().add(myPanel);

myPanel.add(new JLabel(myMessage));

yesButton = new JButton("Yes");

yesButton.addActionListener(this);

myPanel.add(yesButton);

noButton = new JButton("No");

noButton.addActionListener(this);

myPanel.add(noButton);

setDefaultCloseOperation(EXIT_ON_CLOSE);

pack();

setLocationRelativeTo(frame);

setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(yesButton == e.getSource()) {

System.err.println("User chose yes.");

answer = true;

setVisible(false);

}

else if(noButton == e.getSource()) {

System.err.println("User chose no.");

answer = false;

setVisible(false);

}

}

}

Thanks and Regards

Kumar.

hotguya at 2007-7-15 3:24:24 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi Guys,

I think the forum has gone dead. I have posted a querry long back a week ago, I have not even got a response.

**** guys. The Administrator of the forum should close this forum I think. There is no use of this forum now.

Bye guys, have a sound sleep................zzzzzzzzzzzzzzzzzz.............zzzzzzzzzz.........

Regards

hotguy................

hotguya at 2007-7-15 3:24:24 > top of Java-index,Desktop,Core GUI APIs...
# 4
> I am using the JGoodies Look and feel (looks2.0.1.jar). you got the response you deserved> There is no use of this forum now.for JGoodies problems, agreednow , be a good little boy and go play elsewhere
Michael_Dunna at 2007-7-15 3:24:24 > top of Java-index,Desktop,Core GUI APIs...
# 5
Hi Micheal,I think, I was in a right mode that this forum guys are in a sound sleep. I haven't got any response here. Please go through the thread once and then try to reply.Now, get up see what your reply was.Good luckRegards,Hotguy................
hotguya at 2007-7-15 3:24:24 > top of Java-index,Desktop,Core GUI APIs...
# 6

> Please go through the thread once and then try to reply.

I only need to read this far

"is not displayed when I was trying to use my custom LookAndFeel"

you have identified the problem, and it is not with swing.

the jgoodies forum is the place most likely to get you a solution. You may get

lucky and someone who uses jgoodies may respond, but so far that appears

not to be the case.

Michael_Dunna at 2007-7-15 3:24:24 > top of Java-index,Desktop,Core GUI APIs...