This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Netbeans generated code force to be editable?

 
Nalaka Gamagelk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been hand coding Swing GUI applications. Now I want to move to NetBeans to create my SWING applications. What are the best practices? Especially I am struck because most of codes are uneditable. Is there a way to make them editable (At least a tweak) other than using design views?

Thanks
Nalaka
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know if that is possible right from the Netbeans IDE. But one way which I had followed was to open the source file in a normal editor and then make the changes there.

But for most of the changes- the UI provides an option. What kind of changes/tweaks are you planning to do?
 
Nalaka Gamagelk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:I dont know if that is possible right from the Netbeans IDE. But one way which I had followed was to open the source file in a normal editor and then make the changes there.

But for most of the changes- the UI provides an option. What kind of changes/tweaks are you planning to do?


I have created my own nested class action listener by implementing ActionListner class. Now I want some of the buttons in the GUI to be listened by my listener. How can I do that? Properties -> Events do not see my coded listener. There fore I want to by code add my action listener to buttons.
 
Maneesh Godbole
Saloon Keeper
Posts: 11085
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question would be more suitable for the IDE forum.
Moving thread.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nalaka info wrote:

I have created my own nested class action listener by implementing ActionListner class. Now I want some of the buttons in the GUI to be listened by my listener. How can I do that? Properties -> Events do not see my coded listener. There fore I want to by code add my action listener to buttons.


You need not set the Action listener from the UI. What you can do is- after the call to initComponents() [dont know the exact name of the method for initializing components] you can add a line there- button.setActionListener()
 
Nalaka Gamagelk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:
nalaka info wrote:

I have created my own nested class action listener by implementing ActionListner class. Now I want some of the buttons in the GUI to be listened by my listener. How can I do that? Properties -> Events do not see my coded listener. There fore I want to by code add my action listener to buttons.


You need not set the Action listener from the UI. What you can do is- after the call to initComponents() [dont know the exact name of the method for initializing components] you can add a line there- button.setActionListener()


Thanks a lot !
calling button.AddActionListener() after call to initComponents() in constructor worked.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that NetBeans keeps backing data for the automatically generated code in a separate file (same name as the .java file, but different extension) and may at will regenerate the code based on information from this separate file, therefore undoing any changes you've made. This is the real reason you should never edit that code.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vajsar wrote:Please note that NetBeans keeps backing data for the automatically generated code in a separate file (same name as the .java file, but different extension) and may at will regenerate the code based on information from this separate file, therefore undoing any changes you've made. This is the real reason you should never edit that code.


I think the code with in initComponents() is auto-generated (along with the required declarations for the components). Adding any code in the region apart from the Non-Editable should be fine.

And Martin Thanks for pointing this out.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't need to edit the non-editable bits, nor is it a good idea, since it would make it impossible to tweak the design using the GUI Editor at a later date. If you really want to, there's nothing to stop you from cutting and pasting the code as text into an new file, but this takes away many advantatges of using the GUI Editor.

The actual design information used to generate the code is in a ".form" file in the same directory on the disk, which is in XML. If you wanted, you could edit this file manually, but you'd have to figure out the format and syntax and it's a lot easier to spend the time learning to use the Editor properly.

You can, however, add new methods and variables to the class, change the constructor, and write the event handling yourself.

You can aslo make some changes to the way the custom code is generated in Options > GUI Builder, and if you right-click on a component, there is an option to "Customize code". I haven't tried it, but it's there.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks a lot !
calling button.AddActionListener() after call to initComponents() in constructor worked.


You don't need to do this. Double click on the button in design view and ActionListener code is automatically created.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luigi Plinge wrote:

Thanks a lot !
calling button.AddActionListener() after call to initComponents() in constructor worked.


You don't need to do this. Double click on the button in design view and ActionListener code is automatically created.


The OP had an requirement where OP wanted to make use of an Inner class already defined.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic