Meaningless Drivel is fun!*
The moose likes IDEs, Version Control and other tools and the fly likes Can Netbeans generated code force to be editable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Can Netbeans generated code force to be editable?" Watch "Can Netbeans generated code force to be editable?" New topic
Author

Can Netbeans generated code force to be editable?

Nalaka Gamagelk
Greenhorn

Joined: Jun 11, 2009
Posts: 4
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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?


Mohamed Sanaulla | My Blog
Nalaka Gamagelk
Greenhorn

Joined: Jun 11, 2009
Posts: 4
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

This question would be more suitable for the IDE forum.
Moving thread.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

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

Joined: Jun 11, 2009
Posts: 4
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

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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

Joined: Jan 06, 2011
Posts: 441

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

Joined: Jan 06, 2011
Posts: 441


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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can Netbeans generated code force to be editable?