Solved

JCheckBoxMenuItem not visible in JOptionPane

Posted on 2007-03-17
8
698 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 42
ejb stateless example 2 19
Adding multiple JVM environments to RedHat 6 7 46
collection output issue 9 36
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

809 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