如何在 JTabbedPane 中拖动选项卡
我正在尝试创建一个 JTabbedPane,其中选项卡通过 SCROLL_TAB_LAYOUT 向左垂直排列。其代码片段如下:
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;
}
但是,我希望具有与鼠标拖动相同的滚动功能,以便它可以用于触摸屏。有没有办法在选项卡上使用鼠标侦听器?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 mouseListner 添加到选项卡本身或选项卡组件。
You can add mouseListners to the tabs themselves or to the tab components.