Friday, November 2, 2007

Java: DII Character Simulator Update #1

Creating the GUI interface for the DII Character Simulator was the next step in this applications development. Unlike in the original draft I decided against using a JComboBox to change between equipment types. Instead I used a nested JTabbedPane for a more professional look.

Of course this became the first obstacle in that I wasn't sure how to nest a JTabbedPane instead of an already existing JTabbedPane. First attempts lead to the tabs showing up, but in a vertical line instead of horizontally, and also leaving quite a bit of wasted white space on the edges. The problem was that the Equipment class was extending a JPanel, so when this was changed to extend a JTabbedPane everything worked out nicely.

Each piece of the GUI was created in its own method and hosted on a separate JPanel, so that they could be organized and formatted independently. As work began a combination of JCheckBoxes (first time this component has ever been used by me), JButtons, JScrollPanes and JLists (also a first) was organized into the needed GUI pieces. The JList component took some research to locate as the component that would do the job I needed. Set to allow only a single selection, this component is the cornerstone to how equipment will be added (and removed) from the virtual character.

Once all of the components were created, the next task was to combine them all into a single JPanel for display purposes. This turned out to be more of a problem than anticipated. Due to the success of the GroupLayout manager with the skill panels I felt this would be the format needed to create the look and feel of the equipment panels. The problem that arose is that I have only 5 components and didn't want to leave any extra white space. The GroupLayout manager kept cutting off part of one of the components, the ItemList Panel, as I was unable to extend this panel vertically. Everything apparently has to remain in their separate rows, no overlap allowed.

Next attempt was a FlowLayout manager, but getting all of the items to line up vertically simply wasn't working. The components would push each other out of the program window. Finally I settled on a compromise. Two panels were created with the GroupLayout manager that each had two components lined up vertically. The third panel, the one containing the ItemList panel was created with FlowLayout manager. Then all three panels were added to the main panel, also using the FlowLayout manager.


I most likely used more panels and layout managers than necessary, however the final result is quite nice and the code isn't too jumbled, so I'm fine with how things worked out. Once the code was finished for the first equipment type, the helm, it could be carbon copied for all of the other equipment items. The only changes came with the weapon panel, where an option to dual wield was added to the ButtonPanel via a JCheckBox and the other change was the jewelry panel, where some of the selection options were removed or renamed such as elite/exceptional/ normal quality options do not apply.

The next step will be to create the final statistic display that will replace the LCS.

1 comment:

Unknown said...

Hi! I would really love to know how you made the nested tabs work. I'm trying to put two tabs inside another tab. And the wierd thing is that only the last .addTab(blabla)) shows up. No more no less. Please e-mail me at: compoxid@gmail.com.