Reputation: 1
I am using Netbeans 8.0.2 i would like to know if there is any way to create a java Jframe without the generated code or if there id any way to edit that code
So to get rid of this (this is the automatically generated code):
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
Upvotes: 0
Views: 282
Reputation:
That automatically generated code is created by Netbeans and the information about read-only sections of code are kept in the java file.
You cannot see those comments as they're stripped from the viewable-source for presentation by Netbeans automagically.
You can modify the autogeneration by clicking Tools > Templates > Swing GUI Forms, and then right clicking the one you want to modify.
Note that this applies to all future autogenerations, not currently generated forms.
To remove or modify those read-only sections for one file, you need to open that file outside of Netbeans and remove:
//GEN-BEGIN:initComponents
and
//GEN-END:initComponents
from the sections you'd like to remove the read-only property from. Then you can modify or delete them to your leisure.
Upvotes: 0
Reputation: 285405
i would like to know if there is any way to create a java Jframe without the generated code
yes:
JFrame myFrame = new JFrame("My Frame"):
Now we're done with the easy part.
The tougher part for you will likely be learning how to create and place components into your GUI when you're not using the NetBeans drag-and-drop GUI builder, and to do this successfully, you'll need to learn all about layout managers. Please go to the tutorial: Laying out Components within a Container.
Other key bits:
Upvotes: 4
Reputation: 2440
Well, you could add your components via your own method versus the initComponents()
.
public class Test extends JFrame
{
public Test()
{
initComponents();
doMyCustomComponents();
}
public void doMyCustomComponents()
{
JFrame frame = new JFrame("Frame");
//do whatever you need to.
...
...
...
}
}
Note. This is a lot more complex because you are essentially writing the "designer" code on your own. You need to layout the UI and manage everything that initComponents would have done for you otherwise.
Upvotes: 2