Solved

JCheckBoxMenuItem not visible in JOptionPane

Posted on 2007-03-17
8
688 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 500 total points
ID: 18741702
No sqaure will be there for it - it is a menu item....
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

773 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