Solved

JCheckBoxMenuItem not visible in JOptionPane

Posted on 2007-03-17
8
704 Views
Last Modified: 2013-12-22
I am having trouble not being able to see a JCheckBoxMenuItem on a JOptionPane. It Checks when you click it it just isn't visible. In addition when turning on the XP Theme in windows it completely disappears except for the text assigned to the JCheckboxMenuItem. I'm including the source:

import javax.swing.*;
import java.awt.event.*;

public class JOptionPaneExamples {    
    public static void main(String[] args) {
       new Samp206GUI();
    }
}

class Samp206GUI {
   JLabel label;
   public Samp206GUI(){
     //Create a new JFrame object
     JFrame theFrame = new JFrame();
     theFrame.setSize(200,57);
     theFrame.setTitle("My Example");
                     
     //Create a JButton
     JButton buttonA = new JButton("JButton in Windows L&F");
     theFrame.getContentPane().add(buttonA);
               
     //Set the L&F for the GUI
     String plafClassName =
        "com.sun.java.swing.plaf." +
           "windows.WindowsLookAndFeel";
     try{
        UIManager.setLookAndFeel(plafClassName);
      }catch(Exception ex){System.out.println(ex);}
       
      //Cause the L&F to become visible.
      SwingUtilities.updateComponentTreeUI(theFrame);

     //Make the whole thing visible
     theFrame.setVisible(true);
     
     //Call JOptionPane
     buttonA.addActionListener(
       new ActionListener(){
         public void actionPerformed(ActionEvent e){
            JDialog m_dialog = null;
            JOptionPane pane = new JOptionPane("Transmit records",
                                JOptionPane.PLAIN_MESSAGE,
                                JOptionPane.OK_CANCEL_OPTION);
            JCheckBoxMenuItem deleteConfirm = new JCheckBoxMenuItem("Delete records from Table");            
            pane.add(deleteConfirm, 1);
            JDialog confirmDialog = pane.createDialog(m_dialog, "Confirm Transmit");
            confirmDialog.show();
             System.exit(0);
         }//end actionPerformed()
       }//end new ActionListener
     );//end addActionListener
     
     // close the JOptionPane
     theFrame.addWindowListener(new WindowAdapter(){
       public void windowClosing(WindowEvent e){
         System.exit(0);}});
   }//end constructor
 }//end GUI class
0
Comment
Question by:mixmates
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18741562
I can see the JCheckBoxMenuItem on my Windows XP/ Java 5.0 laptop and it also lets me check/ uncheck if I run your code. Can you explain the problem in more detail?

BTW instead of show () you should use setVisible ( true ) as the former is deprecated.
0
 

Author Comment

by:mixmates
ID: 18741696
Thanks on the setVisible, I can check and uncheck but with the windows look and feel on I don't see the checkbox - I see the checkmark show up when I click the checkbox but the square for the box isn't there. If I turn xptheme on then the whole thing is dicolored but the text is there.  I am running the same as you as far as environment is concerned.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 500 total points
ID: 18741702
No sqaure will be there for it - it is a menu item....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mixmates
ID: 18741721
Ok didn't understand that aspect of it, it shows on without the windows look and feel. If I use a regular checkbox it's moved off way to the right. I'm awarding the points as is just curious if you know a way to do it with a checkbox - are gridbox layouts or something similair possible in a JOptionPane?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18741727
For such customized dialog boxes, I would say a modal JDialog is a better option - I won't use JOptionPane as you can't do much with it.
0
 

Author Comment

by:mixmates
ID: 18741734
I thought something like that may be the answer, constantly learning Thanks much for the help.

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18741746
Glad to.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18741747
Menu items are usualy used with menus and not as stand alone....
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question