?
Solved

JCheckBoxMenuItem not visible in JOptionPane

Posted on 2007-03-17
8
Medium Priority
?
753 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: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 2000 total points
ID: 18741702
No sqaure will be there for it - it is a menu item....
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

864 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