JTabbedPane Achieve mouse change height

59 Views Asked by At

Idea has a console window that looks like it's implemented with JTabbedPane

Console window image:

https://i.stack.imgur.com/i9LAx.png

Can change the size by hovering over it:

https://i.stack.imgur.com/bTzen.png

How do implement this UI effect in Swing?

JTabbedPane can have a similar effect, but cannot change the height with the mouse.

1

There are 1 best solutions below

0
RichardTang On

I solved my problem based on FlatLaf and put the code on GitHub.

https://github.com/Richard-Tang/FlatLafTabFrame

show

@Override
public void mouseDragged(MouseEvent e) {
    if (isDragged) {
        Dimension size = getSize();
        size.height += clickDraggedPanelPosition;
        size.height += Math.negateExact(e.getY());
        setPreferredSize(size);
        updateUI();
    }
}

The key code is to change the height of the JPanel with setPreferredSize() and UpdateUI() as you drag.