简体   繁体   中英

Automatically reduce a JPane inside of a JSplitPane to the optimum

in my JFrame I got a JPanelSplitPane and a TabbedPane. On the left side of the SplitPane I got a ScrollPane which includes a JTable. On the right side I got a JPanel which includes some formular data like JTextEdit and so on...

One minor problem I got with tje JSplitPane is, that after a program start, the JPane on the right side has a width of eg 30% of the whole program frame. When I click on the divider, the right Pane will be reduced on the minimum level. How can I improve my code in order to automatically set up the minimum level of the right JPanel? Because this size is the perfect one!

Here is my suggestion, but it dont work as expected:

int iFrameWidth = getWidth();
int iTableCustomer = scrollPaneCustomer.getWidth();
int iSizePaneDetailCustomer = PaneDetailCustomer.getMinimumSize().width;
int iSizeLeft = iFrameWidth-iTableCustomer-iSizePaneDetailCustomer;
int iDividerLocationCustomer = iSizeLeft+iTableCustomer;
SplitPaneCustomer.setDividerLocation(iDividerLocationCustomer);

How can I improve my code in order to automatically set up the minimum level of the right JPanel?

Override the getMinimumSize() method of the right panel:

@Override
public Dimension getMinimumSize()
{
    return super.getPreferredSize();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM