469,366 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

how to edit grayed out area of GUI in NetBeans?

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.
Nov 24 '08 #1
35 40477
Dököll
2,364 Expert 2GB
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!
Nov 25 '08 #2
myusernotyours
188 100+
@ValValVal
The link you gave says in part...
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.
Nov 25 '08 #3
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.
Nov 25 '08 #4
myusernotyours
188 100+
@ValValVal
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.
Nov 25 '08 #5
myusernotyours
188 100+
@ValValVal
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.
Nov 25 '08 #6
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.
Nov 25 '08 #7
r035198x
13,262 8TB
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.
Nov 25 '08 #8
Well it seems sometimes that NetBeans editor is not without flaws.
Val.
Nov 25 '08 #9
myusernotyours
188 100+
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.
Nov 25 '08 #10
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.
Nov 25 '08 #11
r035198x
13,262 8TB
@ValValVal
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.
Nov 26 '08 #12
myusernotyours
188 100+
@r035198x
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.
Nov 26 '08 #13
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).
Nov 26 '08 #14
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!
Apr 25 '09 #15
dorito
18
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
Jun 28 '09 #16
myusernotyours
188 100+
@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.
Jun 29 '09 #17
dorito
18
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
Jun 29 '09 #18
myusernotyours
188 100+
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.
Jun 30 '09 #19
dorito
18
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
Jun 30 '09 #20
myusernotyours
188 100+
@dorito
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.
Jun 30 '09 #21
JosAH
11,448 Expert 8TB
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
Jun 30 '09 #22
myusernotyours
188 100+
@JosAH
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.
Jun 30 '09 #23
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.
Jul 9 '09 #24
dorito
18
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
Jul 17 '09 #25
myusernotyours
188 100+
@dorito
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.
Jul 17 '09 #26
Humakt
42
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.
Jul 17 '09 #27
dorito
18
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
Jul 17 '09 #28
myusernotyours
188 100+
@dorito
The default for each container is the GroupLayout. You have to set the layout for each container you add.

Regards,
Alex.
Jul 18 '09 #29
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,
Aug 12 '09 #30
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.
Aug 12 '09 #31
Ok I also found an article on how to edit the gray blocks here http://stackoverflow.com/questions/4...n-netbeans-6-5
Aug 12 '09 #32
h3rne
1
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!
Oct 24 '09 #33
Vuccli
1
Hi all!
I wish to write it down here, hoping that it will be useful for some guys (because it took me 1-2 hours to realize it, and we know, time is expensive) that gray code in Netbeans GUI builder IS editable!

Every generated code is attached to some element on the GUI. If you want to change some code, you just have to go to the participated element's Properties window, there switch to Code option, and there you can override EVERY gray code that you wish (if you now what is it for, of course.. because you choose the overriden code like "pre-creation code" or "post init code" and so on)

Netbeans just make sure, that you know what you doing. Simple and safe :) wow

(the actionlistening also editable, Properties Event option, as wrote down before me)

I wrote this down, because i'd just started to hate Netbeans, before i figured this out, and that would be unfair..

Hope this help!
Jan 15 '10 #34
I have been wanting to delete an ActionListener for a while but it was referenced in a grey area of code.

As a novice with Netbeans I think part of the problem is the Netbeans help pages. The section on "Safely Deleting Java Code" discusses "References to selected elements were found" but only gives part of the way of deleting these references.

It would be most helpful if something based on the words posted by h3rme on 24 Oct 2009 were added to the "Safely Deleting Java Code" help page.
Jul 21 '10 #35
tezzer
1
This is an old topic, but it comes up high in google searches, so here's how I solved the problem:

The original poster was looking to delete event handlers that were automatically created by NetBeans, but that were no longer needed. You can't do this by editing code; you do it through the GUI like so:

1) Go to the "Design" pane and select the component whose handlers you want to remove

2) On the right hand side of the NetBeans screen, look at the "Properties" window, and select "Events"

3) Find the event you want to remove in the list, hit the ellipsis "...", and use the panel that pops up to remove the event handler you don't want anymore. The auto-generated code will be removed.

I found this information here: http://www.qtp.ufl.edu/slaterlab/hpc...e/visual39.htm
Oct 15 '11 #36

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Richard C. Eberhardt | last post: by
reply views Thread by Brett Romero | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.