views:

129

answers:

1

hi, im making a search function for a database that uses a jtabbedpane with one tab for a quick search, and one for an advanced search. the advanced search has quite a few more fields, so it needs to be larger, but i dont want the whole window to always be at the largest size for aesthetic reasons. i have added a change listener to the pane, and tried resizing the pane based on which tab it is, and the code executes when the tab is clicked, but does nothing. ive tried using tabbedSearchPane.setSize() followed by tabbedSearchPane.validate(), as well as resizing components around it using setSize+validate, and nothing seems to do anything. i really just need to know how to ACTUALLY change the size of a jtabbedpane.

A: 

As described in Preferred Size in Tabs, and as you observed, JTabbedPane tries very hard do to accommodate the largest pane. To switch from the larger to the smaller, you have to replace the larger pane with a temporary one having the same size as the smaller and invalidate() the tabbed pane; the converse is required to go the other way. It's a struggle. Alternatively, consider using CardLayout, mentioned here. As you will want to resize the enclosing container, note how this related example uses pack() accordingly.

trashgod