0

I want to change the state of checkBox menuItems(Enabled or Disabled) for particular document not for all Documents.For example In my application, I create Multiple Documents and I want enabled the Viewspace checkbox menuItem for doc1,It was enabled for all the created Documents not for Doc1 only.Here problem is Checkbox is enabled for only Doc1 not for all.Please give me some suggestions or if possible please provide an example.

My code:

public class ResetState extends javax.swing.JFrame {
int i=0;
JTextPane textPane;
public ResetState() {
    initComponents();
    viewSpaces.setSelected(false);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    tabbedPane = new javax.swing.JTabbedPane();
    menuBar = new javax.swing.JMenuBar();
    file = new javax.swing.JMenu();
    create = new javax.swing.JMenuItem();
    viewSpaces = new javax.swing.JCheckBoxMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    file.setText("File");

    create.setText("Create");
    create.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            createActionPerformed(evt);
        }
    });
    file.add(create);

    viewSpaces.setSelected(true);
    viewSpaces.setText("ViewSpaces");
    viewSpaces.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            viewSpacesActionPerformed(evt);
        }
    });
    file.add(viewSpaces);

    menuBar.add(file);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 279, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>                        

private void createActionPerformed(java.awt.event.ActionEvent evt) {                                       
    final JInternalFrame internalFrame = new JInternalFrame("");
    i++;
    internalFrame.setName("Doc "+i);
    internalFrame.setClosable(true);
    internalFrame.setAutoscrolls(true);
    textPane=new JTextPane();
    internalFrame.add(textPane);
    tabbedPane.add(internalFrame);
    tabbedPane.setSelectedIndex(i-1);
    internalFrame.addInternalFrameListener(new InternalFrameListener() {
        @Override
        public void internalFrameOpened(InternalFrameEvent ife) {
        }
        @Override
        public void internalFrameClosing(InternalFrameEvent ife) {
        }
        @Override
        public void internalFrameClosed(InternalFrameEvent ife) {
        }
        @Override
        public void internalFrameIconified(InternalFrameEvent ife) {
        }
        @Override
        public void internalFrameDeiconified(InternalFrameEvent ife) {
        }
        @Override
        public void internalFrameActivated(InternalFrameEvent ife) {
          viewSpaces.setSelected(false);
        }
        @Override
        public void internalFrameDeactivated(InternalFrameEvent ife) {
        }
    });
    internalFrame.setSize(internalFrame.getMaximumSize());
    internalFrame.pack();
    internalFrame.setVisible(true);       
}                                      

private void viewSpacesActionPerformed(java.awt.event.ActionEvent evt) {                                           


}                                          

public static void main(String args[]) {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(ResetState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(ResetState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(ResetState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(ResetState.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new ResetState().setVisible(true);
        }
    });
}                    
private javax.swing.JMenuItem create;
private javax.swing.JMenu file;
private javax.swing.JMenuBar menuBar;
private javax.swing.JTabbedPane tabbedPane;
private javax.swing.JCheckBoxMenuItem viewSpaces;                  

}

user3912886
  • 53
  • 2
  • 9
  • Welcome to StackOverflow. There are a couple of things wrong with your question that you should fix. 1. Your code block is way to big. You need to provide the specific code that you think is causing the problem rather than posting the entire class. 2. Your problem description seems to be unclear as to what you actually want to accomplish. – JamesENL Aug 06 '14 at 05:55
  • Possible [respost](http://stackoverflow.com/questions/25030089/how-to-reset-the-check-state-and-uncheck-state-of-menuitems-for-multiple-documen) – MadProgrammer Aug 06 '14 at 05:58
  • Hi,I had change the my code and Description.In my Application more code is generated by Netbeans IDE.I had write code only for createAction().Please check it once. – user3912886 Aug 06 '14 at 06:18
  • Here's a stupid question...why are you adding a `JInternalFrame` to `JTabbedPane`? `JInternalFrame`s are suppose to be added to `JDesktopPane`- see [How to Use Internal Frames](http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html). Here's even a stranger idea, why not create a `JMenuBar` for `JInternalFrame` and apply it directly to the `JInternalFrame` (for those items that have local context to the `JInternalFrame`....? – MadProgrammer Aug 06 '14 at 06:24
  • Thank you but,What's the problem with JTabbedPane over JDesktopPane?. – user3912886 Aug 06 '14 at 06:52
  • The problem is, that's not how it's suppose to work. `JDesktopPane` is a container for `JInternalFrame`s which acts like a "mini" desktop, allowing the user to manage a series of windows within it. `JTabbedPane` is suppose to be used for display of a single component, but allow the user to switch between these views...you're mixing metaphors... – MadProgrammer Aug 06 '14 at 06:56
  • For example, if I click the little red "x" on the `JInternalFrame`, I expect it to close, but what does this mean for the tab?? – MadProgrammer Aug 06 '14 at 06:56
  • Oh! I had wrote the code for close the JInternalFrame that is working.But I had not include in this application.But,By using JTabbedpane with JInternalFrame,If open a documents it looks like an Editor.But,with JDesktopPane is not like that.that's why I choose JTabbedPane.Please think on my above specified problem of original post. – user3912886 Aug 06 '14 at 07:08
  • The get rid of the `JInternalFrame` and simply apply the `JTextPane` to the `JTabbedPane`...If looked at it went "huh?" - Imagine what a user is likely to do... – MadProgrammer Aug 06 '14 at 07:16
  • Okay can you provide solution for my problem. – user3912886 Aug 06 '14 at 07:28
  • I did, third comment... – MadProgrammer Aug 06 '14 at 08:00
  • I cann't understand what are you said.can you provide an example for that. – user3912886 Aug 06 '14 at 08:22
  • Where is `viewSpaces.setSelected()`? – Catalina Island Aug 06 '14 at 10:29
  • viewSpaces.setSelected() is available in constructor of ResetState class. – user3912886 Aug 06 '14 at 10:34
  • @Catalina Island please try it once,Thank you. – user3912886 Aug 07 '14 at 05:32
  • I want every action individual to particular Document only.For example I check viewSpaces to Doc1 then I open Doc2,here viewspace must be uncheck upto manually check.Please check it once.I had tried this for long time.But,I didn't get idea. – user3912886 Aug 11 '14 at 07:09
  • Please do this one.I had tried this from past 3 weeks.But,I couldn't get the solution.Anybody help me.Thank you. – user3912886 Aug 21 '14 at 07:18

0 Answers0