如何在 JTabbedPane 中拖动选项卡 [英] How can I drag tabs in JTabbedPane

查看:40
本文介绍了如何在 JTabbedPane 中拖动选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SCROLL_TAB_LAYOUT 创建一个带有垂直向左排列的选项卡的 JTabbedPane.代码片段如下:

<预><代码>私有组件 createTabbedPane(){JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);for (int i = 0; i <20; i++) {JPanel 窗格 = new JPanel();pane.add(new JLabel("这是面板" + i));tabbedPane.addTab("Tab " + i, 窗格);}返回tabbedPane;}

但是,我希望在拖动鼠标时具有相同的滚动功能,以便它可以用于触摸屏.有没有办法在选项卡上使用鼠标侦听器?

解决方案

您可以将 mouseListner 添加到选项卡本身或选项卡组件.

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?

解决方案

You can add mouseListners to the tabs themselves or to the tab components.

这篇关于如何在 JTabbedPane 中拖动选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆