Newbie
Newbie

Reputation: 1714

Design Java GUI with Netbeans

I am new to Netbeans, and I am currently using Netbeans 8.1.
I have a problem with GUI design, Netbeans provide very convenient way to design GUI, which is like "Drag & Drop", but if I do GUI with it, the code which are generated by IDE itself, are not editable, like the function initComponents().
Although Netbeans provide the component's properties menu (I don't know what does it called) like the image below:
enter image description here

But sometimes I still prefer customize the components by using code.
For example: I want to make a JLabel underlined, I will use the code below to make it:

Label1.setText("<HTML><U>YOUR TEXT HERE</U></HTML>");
JLabel1.setDefaultCursor(Cursor.Hand);

But I don't know where should I put this code in, since initComponents() is not editable. Could anyone help me? In a nutshell, is there any method to design GUI by using "Drag & Drop" and also by the code at the same time?

Upvotes: 0

Views: 583

Answers (3)

Manikant Gautam
Manikant Gautam

Reputation: 3581

Yes of course you can add your own methods .You can create your own methods and call it inside your JFrame constructor.

   //     inside your JFrame constructor().
                  JFrame()
                  {  
                      initComponents();
                      customLabel();
                  }
                   private void customLabel()
                  {
                  // your own custom code...
                  Label1.setText("<HTML><U>YOUR TEXT HERE</U></HTML>");
                  Label1.setDefaultCursor(Cursor.Hand);
                  }

There is no need to edit initComponents() method.However You can implements your own code , in order to enhance functionality. .

Upvotes: 0

user5648050
user5648050

Reputation:

All prefferences are inside NetBeans

first

next step

Upvotes: 0

MadProgrammer
MadProgrammer

Reputation: 347184

Netbeans "protects" the initComponents (and other) method from being edited in the ide, it's also not recommended to modify it externally as the ide uses an external (form) file to store the ui state and can regenerate this (and) other methods

Once initComponents has been called (normally in the constructor) , you can interact with components which are created like any other Java object (because they are), they are normally created as instance fields so they should be accessible from within your current class

Upvotes: 1

Related Questions