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

C

clusardi2k

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.

Thank you,
 
A

Arne Vajhøj

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.

NetBeans GUI Builder has traditional been one way.

Maybe you should do like most other Java GUI developers do: use the
GUI builder to learn things but write the real code yourself.

Arne
 
M

markspace

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.
 
J

John B. Matthews

How can I modify the code automatically created by Netbeans.
Some of that code appears to be uneditable.

Anything you can't change in an appropriate Code Property?
Or the component's Customize Code dialog?

[...]
The reason I want to do this is the [Palette] (in design view)
doesn't have things that I need such as modal window capabilities
(jdialogs),

Dialog & Option Pane are under Swing Windows.

[...]

Nothing says you have to use it for _everything_.
 
L

Lew

markspace said:
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.
 
J

John B. Matthews

[QUOTE="Lew said:
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.[/QUOTE]

Exactly; there's a related example here:

<http://stackoverflow.com/a/10468877/230513>

Also, add editor-managed panel(s) to a conventional top-level container,
as shown here:

<http://stackoverflow.com/a/2561540/230513>
 
N

Nigel Wade

How can I modify the code automatically created by Netbeans. Some of
that code appears to be uneditable.

You can't. It's created by NetBeans as determined by the properties of
each of the palette components in the form. If you start making ad hoc
changes to the code the relationship between the form and the code will
be broken.

NetBeans provides you with many facilities to modify the code which is
generated. Much of the functionality of the component is set in the
Properties window for that component. The most flexible customization is
in available in the "Code" tab of the Properties window. Here you can
enter your own code at specific points during the
construction/initialization steps of the component.
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.

Of course, by doing this you have explicitly broken the relationship
between the form and the Java code created from it.
Ok experts, what can I do.

Look at all the properties of the component and see if any of them can
do what you require.
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.

If this is related to you other question regarding modal dialogs, then I
would recommend you start here:
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

The simplest modal dialog is the JOptionPane.

Otherwise you can create your own JDialog. This might be in the main
GUI, as the "Other Components" section of the form, or a separate class
auto-created by the "new JDialog form". A JDialog in the form editor
does have the modal property, which is a toggle button in the main
Properties for the object. I have no knowledge of JLayer, but you can
probably do what you want via the Properties/Code tab of whatever
component in the form is most suitable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top