java - 如何在JTabbedPane后台添加按钮?

标签 java swing jtabbedpane

我想像 Google Chrome 一样在我的 JTabbedPane 背景中添加按钮,这样每次我都可以通过单击它来添加新标签。

enter image description here

我该怎么做?提前致谢!

编辑:我使用了一个未修饰的 JFrame。

最佳答案

查看 JTabbedPane.setTabComponentAt( int index, Component component )方法。此方法允许您设置用于呈现标题的组件。

文档描述:

Sets the component that is responsible for rendering the title for the specified tab. A null value means JTabbedPane will render the title and/or icon for the specified tab. A non-null value means the component will render the title and JTabbedPane will not render the title and/or icon.

Note: The component must not be one that the developer has already added to the tabbed pane.


你可以做什么:

  • 创建JTabbedPane
  • 向其添加一个新标签,其预期功能类似于 chrome 的“添加标签页”
  • 将该选项卡的标题组件设置为按钮(适当设置样式)
  • 单击该按钮时,在按钮选项卡之前添加一个新选项卡并显示新添加的选项卡

关于java - 如何在JTabbedPane后台添加按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41133515/

相关文章:

java - 从 Swing 应用程序创建 Web 应用程序

java - setAlignmentY 不在 BorderLayout 中将 JLabel 居中

java - java命令行上的非确定性进度条

java - 重新解析和映射列表中的元素

java - ActionListener 在 Java 中不工作

Java JTextField 无法输入

Java Swing : Add tabs into JPanels

java - 我如何在 JTabbedPane 的选项卡中添加 JScrollPane

java - 更改 JTabbedPane 标题的大小

java - 仅当选择文件夹时才显示 Eclipse 插件弹出菜单