Solved

JCheckBoxMenuItem not visible in JOptionPane

Posted on 2007-03-17
8
672 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
  • 5
  • 3
8 Comments
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
Comment Utility
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:
mayankeagle earned 500 total points
Comment Utility
No sqaure will be there for it - it is a menu item....
0
 

Author Comment

by:mixmates
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
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
Comment Utility
I thought something like that may be the answer, constantly learning Thanks much for the help.

0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Glad to.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
Menu items are usualy used with menus and not as stand alone....
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now