Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #18324

Re: Netbeans "form" code is uneditable unless copy/paste into new java file

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Netbeans "form" code is uneditable unless copy/paste into new java file
Date 2012-08-26 20:40 -0700
Organization albasani.net
Message-ID <k1eq7g$5hg$1@news.albasani.net> (permalink)
References <08941df4-43d5-4db8-acad-62149e87263c@googlegroups.com> <k1dpiq$2a1$1@dont-email.me>

Show all headers | View raw


markspace wrote:
> clusardi2k@aol.com wrote:
>> How can I modify the code automatically created by Netbeans. Some of
>> that code appears to be uneditable.
>>
>> Instead, I can copy the code, delete the form file it was in, and
>> paste the code into a new class. But, the form disappears. At this
>> code I have all the code, but I lose the "Design" view entirely.
>>
>> Ok experts, what can I do.
>>
>> The reason I want to do this is the Swing pallet (in design view)
>> doesn't have things that I need such as modal window capabilities
>> (jdialogs), and Jlayer capabilities (for a light box effect). Am I
>> wrong about this.
>
>
> First, don't make JFrames forms.  Make JPanels.  You can add a JPanel to a
> JDialog.  I haven't played with JLayer, but a quick read-through of their docs
> makes it appear that you can reasonably expect to add a JPanel to one as well.
>
> Then, when you still need to modify code for you JPanel forms, just don't
> modify the code the IDE generates.  There's an initComponents() method where
> all the non-modifiable code goes.  After initComponents() method is called,
> put your code there.
>
>    MyJPanel() {
>      initComponents();
>      ... add your code here...
>    }
>
>    initComponents() {
>      ... can't modify this ..
>    }
>
> Likewise, you can just add arbitrary methods to the JPanel to do whatever you
> need.
>
>    void changeMyProperty( SomeProperty p ) {
>       //  ... do stuff...
>       jLabel1.setText( p.someString() );
>       jTextField1 = new JTextField();
>    }
>
>    // Instance fields added by NetBeans
>    private void JLabel jLabel1;
>    private void JTextField jTextField1;
>
>
> Basically you have to know Java programming, and then just do the obvious
> thing.  But I realize it can be hard to get started sometimes, so the above
> few hints should help you out.

Apropos of markspace's advice, the NetBeans GUI builder lets you link your 
custom methods to the events you want to handle via the properties pages for 
your screens. So you wire up those arbitrary methods to be called by the 
uneditable parts that MB provides. Best of both worlds.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Netbeans "form" code is uneditable unless copy/paste into new java file clusardi2k@aol.com - 2012-08-26 07:44 -0700
  Re: Netbeans "form" code is uneditable unless copy/paste into new java file Arne Vajhøj <arne@vajhoej.dk> - 2012-08-26 10:50 -0400
  Re: Netbeans "form" code is uneditable unless copy/paste into new java file markspace <-@.> - 2012-08-26 11:23 -0700
    Re: Netbeans "form" code is uneditable unless copy/paste into new java file Lew <noone@lewscanon.com> - 2012-08-26 20:40 -0700
      Re: Netbeans "form" code is uneditable unless copy/paste into new java file "John B. Matthews" <nospam@nospam.invalid> - 2012-08-27 01:47 -0400
  Re: Netbeans "form" code is uneditable unless copy/paste into new java file "John B. Matthews" <nospam@nospam.invalid> - 2012-08-26 14:54 -0400
  Re: Netbeans "form" code is uneditable unless copy/paste into new java file Nigel Wade <nmw@ion.le.ac.uk> - 2012-09-03 10:39 +0100

csiph-web