• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Copy GUI To a Button ?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello , i have come to an idea to make a program performance even better also it creates less forms so we can create a bigger tools , but my question is how can i copy GUI Components and paste it in a button i have tried to copy the whole class jframe code and paste it inside a button but it gives me an error .

i mean i want to copy a GUI from static to dynamic here is an example :

i created a new Form then added jpanels , labes , buttons , textfields etc.

after that i want to copy this form in a Single Button and delete the form itself from the project so when the user click on this button it opens the form with the same components i added in the GUI .

how is it possible to make that happens ?

i am trying to figure out how can i do this but there is no luck for me :/
 
Saloon Keeper
Posts: 10428
223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is possible, but it's really not recommended. Why would you couple a form so tightly to a button? Why don't you want to leave it up to client code to decide how the form is summoned? What makes you think this will affect performance in any way?
 
omar tawfeek
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Yes, this is possible, but it's really not recommended. Why would you couple a form so tightly to a button? Why don't you want to leave it up to client code to decide how the form is summoned? What makes you think this will affect performance in any way?



it will help with doing Database tools with java , it helps alot in this kind of stuff , by doing a button getting table name then adds a button for each table they have in database when they click on this button it will automaticly generate a form with database information with Insert , Delete , Update , Search (in JTable) .

im trying to learn but it comes to mind that you can make tools with this method .
 
omar tawfeek
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for double post but there is no edit here ,

i will do a setting that will let the client choose GUI color and background image this is why i want to generate the form into a button then save it into a file then when he creates his background color or image and font color for his choice it saves the GUI with the client choosed colors so the client be satisfied when he creates his own GUI color thats why i want to know how to put GUI Into a button .
 
Stephan van Hulst
Saloon Keeper
Posts: 10428
223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with just writing a reusable form class that contains a show() method that you can call from a button's action listener?

You can consider giving your form class a constructor that accepts prepared statements for your CRUD operations. You can then create custom instances of TableModel and TableColumnModel based on the parameters in the prepared statements. All you have to do next is create a JTable from those instances and stick it on your form.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!