File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JDialog resize question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog resize question" Watch "JDialog resize question" New topic

JDialog resize question

seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59

I have a JDialog. I add components(label, buttons, checkbox, panel) to it. The panel holds
a scrollpane with a jtable. The table contents change depending on the checkbox selection.
The table shows 3 rows of data when the checkbox is not selected and 7 rows of data when the
check box is selected. I do not want the vertical scroll bars to be displayed instead would
like the dialog to change the size depending on the check box selection. Is this possible?
Any hints?

Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
Hi seema,

Yes, it's possible. First, if the JScrollpane is not used, remove it from the panel. When you add or remove components from the dialog, call pack() to resize the dialog. This will cause the LayoutManager to layout the components again, and resize the dialog if needed.
Here is a sample dialog I did in Netbeans: take a look at the AddRemoveCheckBoxItemStateChanged method.

Notice that the LayoutManager determines how the dialog is resized.

[ May 17, 2007: Message edited by: Darrin Cartwright ]

Life is good on the Ponderosa,<br />but mind where you step.
I agree. Here's the link:
subject: JDialog resize question
It's not a secret anymore!