Connecting Tech Pros Worldwide Help | Site Map

how to edit grayed out are of GUI in NetBeans?

  #1  
Old November 24th, 2008, 10:27 PM
Newbie
 
Join Date: Oct 2008
Posts: 27
Please sorry for my dumb question but I cannot find information on how I can change settings so that in NetBeans 6.1 I can edit blue guarded areas.

I read in FAQ NetBeans Wiki: FaqFormEditingGuardedBlocks that I had to change something in Properties->Code ,but I really can't figure out what this should be.

Thanks in advance.
  #2  
Old November 25th, 2008, 04:23 AM
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,200

re: how to edit grayed out are of GUI in NetBeans?


Hey there!

No dumb questions here:-) But I am not at leisure to help you right now, I will grab my notebook, it has NetBeans installed, then I'll have a look. The text included in your link seems quite fetching though... what happens when you try what is said?

In a bit!

Last edited by Dököll; November 25th, 2008 at 04:23 AM. Reason: text...
  #3  
Old November 25th, 2008, 06:24 AM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by ValValVal View Post
Please sorry for my dumb question but I cannot find information on how I can change settings so that in NetBeans 6.1 I can edit blue guarded areas.

I read in FAQ NetBeans Wiki: FaqFormEditingGuardedBlocks that I had to change something in Properties->Code ,but I really can't figure out what this should be.

Thanks in advance.
The link you gave says in part...
Quote:
However, please note that you can easily write your code out of the guarded block, typically into the constructor after the initComponents() method call, as additional setup code that should be performed. This option is often forgotten, but it is the most eficient and easiset way to add custom code, working in most situation (e.g. except custom instantiation code).
Have you tried that? I find it works for me all the time.
Just put whatever you want to do after initComponents() then if you need to change something there, it's always a breeze.
Or you have a special reason why you want to change the generated code directly??

Regards,

Alex.
  #4  
Old November 25th, 2008, 06:49 AM
Newbie
 
Join Date: Oct 2008
Posts: 27

re: how to edit grayed out are of GUI in NetBeans?


Hi!
I have no special needs to edit it, but still want to know to get more knoledge about the system ,and sometimes NetBeans generates bad code. In these cases I must help him out.
  #5  
Old November 25th, 2008, 07:06 AM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by ValValVal View Post
Hi!
I have no special needs to edit it, but still want to know to get more knoledge about the system ,and sometimes NetBeans generates bad code. In these cases I must help him out.
Then do as it says on your link. Right click the component go to properties then code tab.

Here you can put your custom initialization code.
And what do you mean NetBeans generates bad code?
Is it that you can initialize components better?

Regards,

Alex.
  #6  
Old November 25th, 2008, 07:09 AM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by ValValVal View Post
Hi!
I have no special needs to edit it, but still want to know to get more knoledge about the system ,and sometimes NetBeans generates bad code. In these cases I must help him out.
Then do as it says on your link. Right click the component go to properties then code tab.

Here you can put your custom initialization code.
And what do you mean NetBeans generates bad code?
Is it that you can initialize components better?
NetBeans just uses the properties you assign to components during design to init the components.

Regards,

Alex.
  #7  
Old November 25th, 2008, 12:29 PM
Newbie
 
Join Date: Oct 2008
Posts: 27

re: how to edit grayed out are of GUI in NetBeans?


So actually I cannot "edit" the code that I have now? Pity if so.
I asked the question mainly because someone asked me about this grey code in NetBeans.

And yes,sometimes NetBeans (I noticed it ) has code that I want to remove. E.g. when I delete a component it crashes the project because there is grey code referring to it which I would like to remove manually.
Thanks ,Val.
  #8  
Old November 25th, 2008, 12:39 PM
Administrator
 
Join Date: Sep 2006
Posts: 12,084

re: how to edit grayed out are of GUI in NetBeans?


If you delete a component that you added using Netbeans tools then Net beans should remove all grey code pointing to it.

P.S I use eclipse.
  #9  
Old November 25th, 2008, 02:30 PM
Newbie
 
Join Date: Oct 2008
Posts: 27

re: how to edit grayed out are of GUI in NetBeans?


Well it seems sometimes that NetBeans editor is not without flaws.
Val.
  #10  
Old November 25th, 2008, 02:36 PM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Netbeans does remove generated code if a component is deleted.
I never encountered a situation when it din't.

Anyone else who encountered Val's problem?

Regards,

Alex.
  #11  
Old November 25th, 2008, 03:36 PM
Newbie
 
Join Date: Oct 2008
Posts: 27

re: how to edit grayed out are of GUI in NetBeans?


Besides, after adding event listener it seems impossible to undo it.
The code connecting event with the form is non-editable. If I delete the code of the listener it won't compile anymore.

Val.
  #12  
Old November 26th, 2008, 06:08 AM
Administrator
 
Join Date: Sep 2006
Posts: 12,084

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by ValValVal View Post
...
The code connecting event with the form is non-editable...
I doubt that. There should be a TODO in that action method allowing you to put your own event handling code.
Perhaps you should be going through the Netbeans tutorial or Sun's introduction to Swing using Netbeans tutorial. That way there is no need for anyone to guess anything.
  #13  
Old November 26th, 2008, 06:30 AM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by r035198x View Post
I doubt that. There should be a TODO in that action method allowing you to put your own event handling code.
Perhaps you should be going through the Netbeans tutorial or Sun's introduction to Swing using Netbeans tutorial. That way there is no need for anyone to guess anything.
I don't doubt it, I Refute it. There is a way to remove the code inside the event listener, but aside from any event handling code put there by the programmer, the generated method stub can't be deleted just by hitting the delete button.

@Val: do as r0 advices. Go through the netbeans tutorial.

Regards,

Alex.
  #14  
Old November 26th, 2008, 09:13 AM
Newbie
 
Join Date: Oct 2008
Posts: 27

re: how to edit grayed out are of GUI in NetBeans?


I didnt say that you can't add your event listening code. It is surely possible.
I said that CONNECTING (initializing) code is grayed out and you cannot edit it.And the code of a listener that is not in TODO section cannot be edited as well. So when I add event listener for e.g. mouse click NetBeans adds code to treat it. I can add code in todo section but cannot edit initializing code and code of a method that is not TODO (it's grayed out).
  #15  
Old April 25th, 2009, 02:18 PM
Newbie
 
Join Date: Apr 2009
Posts: 1

re: how to edit grayed out are of GUI in NetBeans?


ValValVal,

Did you ever find a solution. I'm having the same issue. I can't edit the source code. sure I can insert code or edit comments but say for eg the line:

stringItem = new StringItem("Hello", "Hello, World!");

I can't edit the text or anthing. If this is the case netbeans is pure rubbish!
  #16  
Old April 26th, 2009, 09:03 PM
Newbie
 
Join Date: Jan 2008
Posts: 21

re: how to edit grayed out are of GUI in NetBeans?


Zzzzzzzzzzzzzzzzzzzzz
Quote:
Originally Posted by mcsean2163 View Post
valvalval,

did you ever find a solution. I'm having the same issue. I can't edit the source code. Sure i can insert code or edit comments but say for eg the line:

Stringitem = new stringitem("hello", "hello, world!");

i can't edit the text or anthing. If this is the case netbeans is pure rubbish!
  #17  
Old June 28th, 2009, 08:44 PM
Newbie
 
Join Date: Jun 2009
Posts: 8

re: how to edit grayed out are of GUI in NetBeans?


I am a newbie to NetBeans ... and I cannot figure out how to get rid of a Panel in the Design View. I mistakenly added it and it is somehow invisible so I cannot select it and delete it. It does show up in the Navigator window, but when I select it there and I do right-click / Refactor / Safely Delete ... it won't let me delete it because there are still references. These references are all within the gray initComponents() code that is automatically generated. It seems I cannot modify this code to remove the references.

How do I get out of this?

Thx,
Dorito
  #18  
Old June 29th, 2009, 01:50 PM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by dorito View Post
I am a newbie to NetBeans ... and I cannot figure out how to get rid of a Panel in the Design View. I mistakenly added it and it is somehow invisible so I cannot select it and delete it. It does show up in the Navigator window, but when I select it there and I do right-click / Refactor / Safely Delete ... it won't let me delete it because there are still references. These references are all within the gray initComponents() code that is automatically generated. It seems I cannot modify this code to remove the references.

How do I get out of this?

Thx,
Dorito
You will need to explain your question better, you mention the navigator window which shows the methods and variables in a particular file. But you are saying that u want to delete the panel. The panel will be visible in the inspector window so I have no idea whether you made a mistake mentioning the navigator window or it's actually where you are.

I will give it a blind shot nonetheless, if you have some event handlers generated by the ide, you cannot delete them via the navigator. You remove them via the properties window of the concerned UI object. If you want to delete a panel that you put on a JFrame, just go to the inspector window, find the panel open the context menu and hit delete. You have the option to do a safe delete or not.

If u delete a panel, all components it contains + all event handlers go.
The generated code adjusts accordingly.


I have encountered a situation where I couldn't delete buttons from a panel, I think it was a bug because when I hit delete, nothing happened, no message no expected results. I had to reinstall netbeans and when I opened the project with the new install, everything went fine.
But I don't think thats the problem u are having because you are getting some response.


Finally, you can never edit the grayed out code, netbeans enforces this and it should never be a problem. If you ever feel that u want to edit this code, think again, there is something that u are not doing right.

And which version of netbeans are we talking about?

Regards,

Alex.
  #19  
Old June 29th, 2009, 05:26 PM
Newbie
 
Join Date: Jun 2009
Posts: 8

re: how to edit grayed out are of GUI in NetBeans?


Alex,

Thanks for taking interest. I have NetBeans 6.5.1. I created a new File of type JDialog and was in the "Design" pane, dragging various Controls over from the Palette. As long as any particular control is visible on the Design area, I can select it and delete it (and the grayed-out code will be updated accordingly). However when I look over in the Navigator view I have a "jPanel1" component that is part of this JDialog. This panel seems to be "invisible" - I cannot select it on the Design view ... it exists only in the initComponents() code and as listed in the Navigator.

I cannot determine how to get rid of it. Refactoring does not work because there are still references to it - namely the automatically-generated references within the initComponents() code which I can't modify. It seems to be a Catch-22 ... I suspect that NetBeans expects me to be able to "see" the jPanel1 control so I can select/'delete it ... but it is no where to be seen.

- Dorito
  #20  
Old June 30th, 2009, 07:19 AM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


What about if you right click on the jpanel in the inspector window notice this is the inspector window that we are talking about here. There will be a delete somewhere on the context menu. Use that.
Actually if you move your mouse over the jpanel on the design view, it will be *highligted* or bordered out and you should be able to see it unless it is too small and you can't get your mouse over it, in which case you use the inspector window.

Regards,

Alex.
  #21  
Old June 30th, 2009, 08:01 AM
Newbie
 
Join Date: Jun 2009
Posts: 8

re: how to edit grayed out are of GUI in NetBeans?


In the Inspector view, there is no JPanel item. There are .java source files, and there are resources, which are basically properties of each Component ... and various other things for the project, but there are no Swing components listed. The JPanel item only shows up in the Navigator view. In the Design view, it does not matter where I move my mouse or click, the hidden JPanel does not get highlighted or border'ed.

I am beginning to believe that NetBeans did not account for the potential "hidden-ness" of such a component. At this point I have several other ones too - scrollbars that I cannot get rid of, that are artifacts of bringing in TextAreas from the palette. I think the NetBeans designers assumed you would always be able to click on these items in the Design view and have them appear. They need to allow the user to see a list of the components that have been dragged from the palette, then allow you to delete from that list.

-Chris
  #22  
Old June 30th, 2009, 01:12 PM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by dorito View Post
They need to allow the user to see a list of the components that have been dragged from the palette, then allow you to delete from that list.

-Chris
That, Chris is what the inspector window is for. Looks like you don't really understand what the inspector window is. Have a look at this.

Regards,

Alex.
  #23  
Old June 30th, 2009, 01:34 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: how to edit grayed out are of GUI in NetBeans?


This was lesson #1 of our 101 course: "How to avoid GUI builders like the plague". Always build your GUI components by hand, know what you're doing and don't let them builders touch any of your code because they won't let go easily. Class dismissed! ;-)

kind regards,

Jos
  #24  
Old June 30th, 2009, 01:59 PM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by JosAH View Post
know what you're doing and don't let them builders touch any of your code because they won't let go easily.

kind regards,

Jos
And if you are a deliquent student like me, go ahead and use the GUI builder but keep far away from the builders code... :)
Builders have a way of saying, *If you wanted to write code, you could have done it yourself to begin with!*

Regards,

Alex.
  #25  
Old July 9th, 2009, 09:54 PM
Newbie
 
Join Date: Jul 2009
Posts: 1

re: how to edit grayed out are of GUI in NetBeans?


Quote:
I will give it a blind shot nonetheless, if you have some event handlers generated by the ide, you cannot delete them via the navigator. You remove them via the properties window of the concerned UI object.
Thank you.

To hopefully clarify for noobs like me, the "Events" tab in the Properties window may not be visible through the Properties pane, but is easily found in the properties window as myusernotyours stated. It also seems that the way to delete event handlers is to delete the text, in that Events tab, which refers to the specific event handler. I found this process slightly counter-intuitive; so, hopefully this helps.
  #26  
Old July 17th, 2009, 08:42 AM
Newbie
 
Join Date: Jun 2009
Posts: 8

re: how to edit grayed out are of GUI in NetBeans?


Well - I now realize that the Inspector window is available when you are in the Design mode ... and yes it is easy to find and modify everything, even invisible stuff.

My GUI application is now almost entirely converted from C to JAVA ... but what is torquing me off right now is that in the Design editor it keeps automatically resizing all my components. It seems it doesn't want to let me move and resize components on my own - is there any way to shut off all this automaticity ?

-Chris
  #27  
Old July 17th, 2009, 09:11 AM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by dorito View Post
Well - I now realize that the Inspector window is available when you are in the Design mode ... and yes it is easy to find and modify everything, even invisible stuff.

My GUI application is now almost entirely converted from C to JAVA ... but what is torquing me off right now is that in the Design editor it keeps automatically resizing all my components. It seems it doesn't want to let me move and resize components on my own - is there any way to shut off all this automaticity ?

-Chris
The netbeans GUI Builder as do other builders use the GroupLayout to manage components. This in my experience makes it tricky, even frustrating, to place components on panels and so on. But if you understand exactly how the GroupLayout lays out the components and why, you are in a better position to lay out your components without much of a hassle. So I'd advise you look at the docs for the GroupLayout class and the Java Tutorials on layouts.

If you want, you could turn off the GroupLayout thing all together and use a NullLayout that will let you put components every which way. This however, is ill advised since your windows may look ok on your machine and OS, but with different machines, OSes, Look and feels, users resizing and so on, there is no telling what will happen. Unless you want to manage all this yourself and test it everywhere.

Regards,

Alex.
  #28  
Old July 17th, 2009, 10:26 AM
Member
 
Join Date: Aug 2008
Posts: 36

re: how to edit grayed out are of GUI in NetBeans?


Nothing is preventing you from using another IDE with the same source code. Eclipse won't be stopping you from editing code made grey by NetBeans.
  #29  
Old July 18th, 2009, 12:08 AM
Newbie
 
Join Date: Jun 2009
Posts: 8

re: how to edit grayed out are of GUI in NetBeans?


I have changed the Layout to NullLayout and it allows me to put panels where I want. However when I put Labels within those Panels they are still moved around automatically in the Design view. I can see in the gray code that it has done a:

getContentPane().setLayout(null);

but then it goes ahead and does:

jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup ... etc. (and also does setHorizontalGroup (...)

I want my jPanel1 to have a Null layout as well so I can put Labels within it wherever I want.

By the way, if I do the following in the constructor (in order to move my Labels to where I want them):

super(parent, modal);
initComponents();
setPreferredSize (new java.awt.Dimension (230,230));
java.awt.Component SP = label3; // move the label
//SP.setLocationRelativeTo (null);
SP.setBounds(100, 50, 37, 37);
SP = label4; // move the label
SP.setBounds(100, 100, 37, 37);

... the setBounds seems to have no effect - like it was ignored.

-Chris
  #30  
Old July 18th, 2009, 07:00 PM
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168

re: how to edit grayed out are of GUI in NetBeans?


Quote:
Originally Posted by dorito View Post
I have changed the Layout to NullLayout and it allows me to put panels where I want. However when I put Labels within those Panels they are still moved around automatically in the Design view. I can see in the gray code that it has done a:

getContentPane().setLayout(null);

but then it goes ahead and does:

jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup ... etc. (and also does setHorizontalGroup (...)

I want my jPanel1 to have a Null layout as well so I can put Labels within it wherever I want.

By the way, if I do the following in the constructor (in order to move my Labels to where I want them):

super(parent, modal);
initComponents();
setPreferredSize (new java.awt.Dimension (230,230));
java.awt.Component SP = label3; // move the label
//SP.setLocationRelativeTo (null);
SP.setBounds(100, 50, 37, 37);
SP = label4; // move the label
SP.setBounds(100, 100, 37, 37);

... the setBounds seems to have no effect - like it was ignored.

-Chris
The default for each container is the GroupLayout. You have to set the layout for each container you add.

Regards,
Alex.
  #31  
Old August 12th, 2009, 05:20 AM
Newbie
 
Join Date: Aug 2009
Posts: 3

re: how to edit grayed out are of GUI in NetBeans?


Hi all,

I'm having the same beef with netbeans right now. I really need to edit the gray area (OR can someone help me fix the actual problem).

The thign is, netbeans seems to have lost its mind, here's my problem. I recently split my projeect into class library / application. components on my forms now dont display and netbeans gives the error that it couldnt find the types ive used. I know what you're thinking, no reference right? wrong, I added the library to the app project, oh so many times ive deleted and re-added it. worse still, all the code within those forms, that use the very same types.. function perfectly, no problem with the import or anything.. but as soon as the netbeans GUI tries to use those types, chucks a spastic and replaces the types with 'invalidtype'. worse yet, when I first set this up, nothing even went wrong, compiled n run no problem, this has happened since i restarted my pc and tried again. It makes no sense.

I am pretty new with netbeans, but no gui should be behaving this way, i've never had this much trouble for such a simple thing.

So I ask if anyone knows. A) how to let me edit the incorrect grayed out code, or B) how to make the GUI recognise these classes like the rest of the code does.

Thanks,
  #32  
Old August 12th, 2009, 05:42 AM
Newbie
 
Join Date: Aug 2009
Posts: 3

re: how to edit grayed out are of GUI in NetBeans?


I've found a workaround, but still looking for a better way.

Telling you my workaround may help you figure out what's wrong. All this talk of classpaths in netbeans got me worried, especially since the classpaths of the form seem to be readonly? so i copied my .jar file and loaded it into the project from within the classes folder of that project, i can now drag components from there, onto my form with no hassles.

I don't like this solution though, I'd much rather it link to my project the way it's meant to, so that when I make changes they'll apply without me having to copy the file over. I see no reason why I shouldn't be able to reference the project or reference the jar file where it is compiled, but neither work. only nested within the project does the GUI recognise these types.

Any idea's of what on earth is going on here? as previously mentioned, the actual code has always worked fine, i can manually code in a class and it will work, but cannot drag it onto the form using the designer.
  #33  
Old August 12th, 2009, 05:55 AM
Newbie
 
Join Date: Aug 2009
Posts: 3

re: how to edit grayed out are of GUI in NetBeans?


Ok I also found an article on how to edit the gray blocks here http://stackoverflow.com/questions/4...n-netbeans-6-5
  #34  
Old October 24th, 2009, 02:59 PM
Newbie
 
Join Date: Oct 2009
Posts: 1

re: how to edit grayed out are of GUI in NetBeans?


I'm a total netbeans noob - but thanks to everyone who contributed - I finally managed to put the pieces together to delete an action listener/event handler pair I didn't want, without messing with the generated code.

Here's my walk though for the other noobs out there:
- Click on the GUI element in design view.
- Bring up the Properties window from the Window menu on the main menu bar, if it's not already visible.
- The properties window has four tabs across the top (except they don't really look like tabs. "Properties, Binding, Events, Code" Probably the Properties one is selected by default, and it looks like a button.
- Click on the "Events" tab. It should change to look like a button.
- There the first line should be "Action Performed". Next to it should be something other than <none> above a whole load of other buttons showing <none>.
- On the far right is a [...] button. Click it.
- In the dialog that appears, click the text for the handler you're trying to remove.
- Click the "remove" button

Feel free to check the source code for the GUI, but both the addlistener and eventhandler code should be gone.

I hope someone finds this useful!
Reply