• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can Netbeans generated code force to be editable?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question would be more suitable for the IDE forum.
Moving thread.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 441
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic