DavideChicco.it
DavideChicco.it

Reputation: 3470

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.

Interface resizing problem

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!

Upvotes: 1

Views: 6196

Answers (1)

Radu Murzea
Radu Murzea

Reputation: 10920

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.

Upvotes: 5

Related Questions