How can I drag tabs in JTabbedPane
I am trying to create a JTabbedPane with tabs arranged vertically LEFT with SCROLL_TAB_LAYOUT. The code snippet for this is as below:
开发者_StackOverflow中文版
private Component createTabbedPane()
{
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT,
JTabbedPane.SCROLL_TAB_LAYOUT);
for (int i = 0; i < 20; i++) {
JPanel pane = new JPanel();
pane.add(new JLabel("This is Panel " + i));
tabbedPane.addTab("Tab " + i, pane);
}
return tabbedPane;
}
However, I want have the same scrolling feature with mouse dragged so that it could be used for touch screen. Is there any way to use mouse listeners on the tabs?
You can add mouseListners to the tabs themselves or to the tab components.
精彩评论