简体   繁体   中英

Java Swing, how to make a JPanel resizable with mouse?

I have been developing an user interface with Java Swing, and I have met a problem in JPanel resizing.

This is my problem: I would like to let a JPanel be resizable by the user, when the user points its mouse over the JPanel border line (as described in the following figure). Now, if I move my mouse over that line, nothing happens. I would like that I could change its size with my mouse.

界面调整大小问题

Here's my code portion:

    JTabbedPane _tabbedPane = new JTabbedPane();
JPanel gridAndCommandPaneValidation = new JPanel(); 
    gridAndCommandPaneValidation.setLayout(new BorderLayout()); 

    ValidationTableModel vtm = new ValidationTableModel(new LinkedList<DatabaseAnalysisValues>());
    tableValidation = new JTable(vtm);
    JScrollPane scrollpaneVal = new JScrollPane(tableValidation);

 tableValidation.setAutoscrolls(true);
    gridAndCommandPaneValidation.add(scrollpaneVal, BorderLayout.WEST);
    gridAndCommandPaneValidation.add(getKBestValidationCommandsPanel(), BorderLayout.EAST);
    _tabbedPane.add("Validation", gridAndCommandPaneValidation);

Is there anyone that can help me?

Many thanks!

Take a look at JSplitPane and the corresponding Java Tutorial . This component can do exactly what you want and it behaves very well. Try the first example in the tutorial, you'll see.

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