how to edit grayed out area of GUI in NetBeans?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorito
    New Member
    • Jun 2009
    • 18

    #16
    related issue ...

    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

    Comment

    • myusernotyours
      New Member
      • Nov 2007
      • 188

      #17
      Originally posted by dorito
      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.

      Comment

      • dorito
        New Member
        • Jun 2009
        • 18

        #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

        Comment

        • myusernotyours
          New Member
          • Nov 2007
          • 188

          #19
          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.

          Comment

          • dorito
            New Member
            • Jun 2009
            • 18

            #20
            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

            Comment

            • myusernotyours
              New Member
              • Nov 2007
              • 188

              #21
              Originally posted by dorito
              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.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #22
                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

                Comment

                • myusernotyours
                  New Member
                  • Nov 2007
                  • 188

                  #23
                  Originally posted by JosAH
                  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.

                  Comment

                  • threepenpals
                    New Member
                    • Jul 2009
                    • 1

                    #24
                    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.

                    Comment

                    • dorito
                      New Member
                      • Jun 2009
                      • 18

                      #25
                      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

                      Comment

                      • myusernotyours
                        New Member
                        • Nov 2007
                        • 188

                        #26
                        Originally posted by dorito
                        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.

                        Comment

                        • Humakt
                          New Member
                          • Aug 2008
                          • 42

                          #27
                          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.

                          Comment

                          • dorito
                            New Member
                            • Jun 2009
                            • 18

                            #28
                            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(nul l);

                            but then it goes ahead and does:

                            jPanel1Layout.s etVerticalGroup (
                            jPanel1Layout.c reateParallelGr oup ... etc. (and also does setHorizontalGr oup (...)

                            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( );
                            setPreferredSiz e (new java.awt.Dimens ion (230,230));
                            java.awt.Compon ent SP = label3; // move the label
                            //SP.setLocationR elativeTo (null);
                            SP.setBounds(10 0, 50, 37, 37);
                            SP = label4; // move the label
                            SP.setBounds(10 0, 100, 37, 37);

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

                            -Chris

                            Comment

                            • myusernotyours
                              New Member
                              • Nov 2007
                              • 188

                              #29
                              Originally posted by dorito
                              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(nul l);

                              but then it goes ahead and does:

                              jPanel1Layout.s etVerticalGroup (
                              jPanel1Layout.c reateParallelGr oup ... etc. (and also does setHorizontalGr oup (...)

                              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( );
                              setPreferredSiz e (new java.awt.Dimens ion (230,230));
                              java.awt.Compon ent SP = label3; // move the label
                              //SP.setLocationR elativeTo (null);
                              SP.setBounds(10 0, 50, 37, 37);
                              SP = label4; // move the label
                              SP.setBounds(10 0, 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.

                              Comment

                              • Phill64
                                New Member
                                • Aug 2009
                                • 3

                                #30
                                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,

                                Comment

                                Working...