问题
I am trying to create a JTabbedPane with tabs arranged vertically LEFT with SCROLL_TAB_LAYOUT. The code snippet for this is as below:
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?
回答1:
You can add mouseListners to the tabs themselves or to the tab components.
来源:https://stackoverflow.com/questions/4376084/how-can-i-drag-tabs-in-jtabbedpane