Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
I have this java code:
	Editor()
	{
		javax.swing.SwingUtilities.invokeLater(new Runnable()
		{
            public void run() 
            {
            	// Create Menu
            	JMenuBar menuBar = drawMenu();
            	frame.setJMenuBar(menuBar);
 
		frame.setUndecorated(true);
		frame.add(desktop, BorderLayout.CENTER);
            	frame.add(toolbar,BorderLayout.NORTH);
            	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            	frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
            	frame.getRootPane().setWindowDecorationStyle(JRootPane.INFORMATION_DIALOG);
            	frame.setTitle("JIL");
            	frame.pack();
            	frame.setVisible(true);
            }
	});
      }
 

        public JMenuBar drawMenu() 
	{
		// Create the menu bar
		JMenuBar menuBar = new JMenuBar();
		// Create a menu
		JMenu file = new JMenu("File");
		JMenu edit = new JMenu("Edit");
		JMenu run = new JMenu("Build");
		JMenu help = new JMenu("Help");
		menuBar.add(file);
		menuBar.add(edit);
		menuBar.add(run);
		menuBar.add(help);
		
		JMenu _new = new JMenu("New");
		file.add(_new);
	
	        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		JButton clsbutton=new JButton(new ImageIcon (classLoader.getResource ("img/cls.jpg")));
		clsbutton.setSize(2, 2);
		clsbutton.setToolTipText("New Class");
		toolbar.add(clsbutton);
		clsbutton.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent event) 
			{	
				new newClass();
			}
		});
           }
 

 
        newClass()
        {
	contentPanelC.removeAll(); 
	getContentPane().removeAll();
	setTitle("New Class");
	setBounds(100, 100, 470, 400);
	getContentPane().setLayout(new BorderLayout());
	contentPanelC.setBorder(new EmptyBorder(5, 5, 5, 5));
	getContentPane().add(contentPanelC, BorderLayout.CENTER);
	contentPanelC.setLayout(null);
	
	JLabel lblNewLabel = new JLabel("Class Name");
	lblNewLabel.setBounds(50, 51, 120, 17);
	contentPanelC.add(lblNewLabel);
	contentPanelC.revalidate();
	contentPanelC.repaint();
	
	textField = new JTextField();
	textField.setBounds(170, 51, 228, 20);
	contentPanelC.add(textField);
	contentPanelC.revalidate();
	contentPanelC.repaint();
	textField.setColumns(10);
	textField.setText(null);
	textField.revalidate();
	textField.repaint();
	
	String fnam=textField.getText();
	System.out.println("Initial value TextField: "+fnam);
	
	JLabel lblNewLabel_1 = new JLabel("Location");
	lblNewLabel_1.setBounds(50, 111, 120, 17);
	contentPanelC.add(lblNewLabel_1);
	contentPanelC.revalidate();
	contentPanelC.repaint();
	
	textField_1 = new JTextField();
	textField_1.setBounds(170, 111, 131, 20);
	contentPanelC.add(textField_1);
	contentPanelC.revalidate();
	contentPanelC.repaint();
	textField_1.setColumns(10);
	textField_1.setText(null);
	textField_1.revalidate();
	textField_1.repaint();
							
	final JButton btnNewButton = new JButton("Browse");
	btnNewButton.addActionListener(new ActionListener() 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			String workingdir = System.getProperty("user.dir");
			chooser = new JFileChooser(new File(workingdir));
		    chooser.setDialogTitle("Select Location");
		    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		    chooser.setAcceptAllFileFilterUsed(false);
 
		    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) 
		    {
		      File selectedFile = chooser.getSelectedFile();
	          System.out.println(selectedFile.getName());
	          textField_1.setText(selectedFile.getPath());
		    } 
		    else 
		    {
		      System.out.println("No Selection ");
		    }
		    btnNewButton.revalidate();
		}
	});
					
	btnNewButton.setBounds(320, 111, 89, 20);
	contentPanelC.add(btnNewButton);
	contentPanelC.revalidate();
	contentPanelC.repaint();
	
	
	{
		
		JPanel buttonPaneC = new JPanel();
		buttonPaneC.removeAll();
		buttonPaneC.setLayout(new FlowLayout(FlowLayout.RIGHT));
		getContentPane().add(buttonPaneC, BorderLayout.SOUTH);
		{
			final JButton okButton = new JButton("Ok");
			okButton.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent arg0) 
				{
					{
					// some file operations
					}
					textField.setText("");
					textField.revalidate();
					textField.repaint();
					
					textField_1.setText("");
					textField_1.revalidate();
					textField_1.repaint();
					
					dispose();
					
				}
			});
			okButton.setActionCommand("Ok");
			buttonPaneC.add(okButton);
			buttonPaneC.revalidate();
			buttonPaneC.repaint();
			getRootPane().setDefaultButton(okButton);
			
		}
		{
			final JButton cancelButton = new JButton("Cancel");
			cancelButton.setActionCommand("Cancel");
			buttonPaneC.add(cancelButton);
			buttonPaneC.revalidate();
			buttonPaneC.repaint();
			
			contentPanelC.validate();
			contentPanelC.repaint();
			cancelButton.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent arg0) 
				{
					dispose();
				}
			});
			
		}
	}
	setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	setVisible(true);
	contentPanelC.validate();
	contentPanelC.repaint();
}
}
 
All time this code results in the following exception:
 
<pre lang="java">
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is displayable.
	at java.awt.Frame.setUndecorated(Frame.java:825)
	at Editor$1.run(Editor.java:93)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:673)
	at java.awt.EventQueue.access$300(EventQueue.java:96)
	at java.awt.EventQueue$2.run(EventQueue.java:634)
	at java.awt.EventQueue$2.run(EventQueue.java:632)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:643)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
 
I have tried my best. What is this?
Even this exception is shown in console the output window appears. But this troubles when I'm trying to debug the code. Somebody please help me.
Posted 29-Mar-13 23:06pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You're codes is too long.. looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 12 Mar 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100