• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design / Development Question

 
Brad Walton
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, I am 'green' to Swing, but past beginner with Java. I am working on the base design of a fairly basic GUI using Swing, which consists of a dozen or so tabs. I would like for each tab to be constructed in its own class file, so that simultaneous work may be done by developers on individual tabs.. And then have it called from a main GUI class file which puts it all together and makes it appear (does that make sense?). All of the JTabbedPane examples I have seen construct the entire GUI in one large class file, rather than seperate files. Does anyone know of any examples, or suggested reading, which would help me understand how to properly achieve this result?

Thanks for any help.
[ February 18, 2008: Message edited by: Brad Walton ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not all that difficult. What I do is create a separate class for each container that will exist in a tab. Then I instantiate each one I need and call tabbedPane.addTab(); Something like this:



Each of the above classes would be in its own file. And that was major pseudo code so use it as a template, not verbatim.
 
Brad Walton
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gregg. Appreciate the help!
 
Brad Walton
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm.. I'm having a little trouble with the construction of it (i.e. in FormOne()). Can you provide a quick example of that? I am getting an error when adding it in Main, which is looking for the String, Component.. I am constructing it as a JTabbedPane in the FormOne class but that doesn't seem to be working.

Thanks again.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brad Walton:
Hmm.. I'm having a little trouble with the construction of it (i.e. in FormOne()). Can you provide a quick example of that? I am getting an error when adding it in Main, which is looking for the String, Component.. I am constructing it as a JTabbedPane in the FormOne class but that doesn't seem to be working.

Thanks again.


Again, my code was just a template. If you look at the API for JTabbedPane.addTab it requires a String as the first argument which will become the Title of the tab. If you continue to have problems, please post your code. It is easier to debug if we have something to look at.
 
Brad Walton
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See next post...
[ February 19, 2008: Message edited by: Brad Walton ]
 
Brad Walton
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I finally got it working, but I am not sure if this is the best way to do it, or the method being described in the template above.

Component creation class:


And in the main GUI class:


Have I got this right? Or is there a better way?

Thanks!
[ February 19, 2008: Message edited by: Brad Walton ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic