- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Nimbus 外观和感觉使用 JTabbedPane
创建一个应用程序
我使用这段代码来放置标签:
pane.addTab("Welcome",new ImageIcon("resources\\1.png"),mainPanel,"Takes to the welcome page");
我想让图标出现在左边
最佳答案
您可以通过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 andJTabbedPane
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.
例如你可以这样做:
JLabel label = new JLabel("Tab1");
label.setHorizontalTextPosition(JLabel.TRAILING); // Set the text position regarding its icon
label.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
tabbedPane.addTab(null, new JPanel());
tabbedPane.setTabComponentAt(0, label); // Here set the custom tab component
屏幕截图 1:
注意:使用此功能,您可以根据需要设置任何Component
。例如,您可以制作一个带有 JButton
的 JPanel
来关闭选项卡:
final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton)e.getSource();
for(int i = 0; i < tabbedPane.getTabCount(); i++) {
if(SwingUtilities.isDescendingFrom(button, tabbedPane.getTabComponentAt(i))) {
tabbedPane.remove(i);
break;
}
}
}
};
JLabel label = new JLabel("Tab1", UIManager.getIcon("OptionPane.informationIcon"), JLabel.RIGHT);
JButton closeButton = new JButton("X");
closeButton.addActionListener(actionListener);
JPanel tabComponent = new JPanel(new BorderLayout());
tabComponent.add(label, BorderLayout.WEST);
tabComponent.add(closeButton, BorderLayout.EAST);
tabbedPane.addTab(null, new JPanel());
tabbedPane.setTabComponentAt(0, tabComponent); // Here set the custom tab component
截图2:
您可能还想查看此主题:JTabbedPane: tab placement set to LEFT but icons are not aligned
关于java - 在 Nimbus Look and Feel 的 JTabbedPane 中将图标左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19787146/
当我 console.log(feelings) 它打印输入的文本值 形式。 但是,当我尝试向对象添加“感觉”并进行更新时 使用它的 ui 我得到 [object Object] 当你使用感觉时,值(
我将 jgoodies-looks-2.5.3.jar 添加到我的构建路径中并使用 启动它 public static void main(String[] args) { Event
我正在尝试找出一种方法来创建在短序列上“感觉”随机的随机数。这是一个问答游戏,其中有四种可能的选择,软件需要在四个位置中选择一个来放置正确答案,然后再用干扰项填充其他三个位置。 显然,arc4rand
这个问题在这里已经有了答案: Java Look and Feel (L&F) [closed] (4 个答案) 关闭 8 年前。 我有 5 个用于工程的 Java 系统,其 UI 是使用 Swin
我正在尝试在我的网站中制作一个程序来测试不同搜索的热门搜索结果是否相同。例如,它应该表明“12”和“12”的顶部搜索结果相同,因为两者的顶部结果都是 https://en.wikipedia.org/
我正在使用 IntelliJ 中的“UI Designer”创建图形用户界面。 不幸的是,我将主题设置为“Nimbus”,但它在主窗口中不起作用。仅适用于新窗口/对话框。 窗口和应用程序的屏幕: 最佳
我有一个 JTable,其中填充了来自 MySQL 表的数据,但是有多个客户端同时更新并插入到数据库中。我的目标是为 Table 提供某种近乎实时的体验。我想每隔 5 秒更新一次 TableModel
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
我有一个 JTable,我为其提供了一个自定义 TableCellRenderer,它根据值 (0) 将数字单元格着色为红色/灰色/绿色。 但是,当我使用 Nimbus L&F 时,label.set
我正在尝试调整 Nimbus 外观的颜色,但它只是部分起作用。特别是我在调整菜单栏的颜色时遇到了问题。 这是一个运行示例: import java.awt.Color; import java.awt
我试图在 JPanel 上调用 setBackground,以便它与我的 JFrame 的颜色相匹配,但是颜色有点比我输入的要亮多少。 我试过设置 HSB、RGB、HEX 代码,它们都给我相同的颜色,
我一直是一名使用 Java 和 Python 的后端开发人员。我将 JQuery 用于诸如验证、数据表和核心 javascript 任务之类的事情。我一直使用 Jquery 的默认 CSS。 我现在的
我正在寻找是否可以更改 Nimbus 外观和感觉中所有组件的全局大小。 有一个tutorial用于重新调整组件大小;但并非适用于所有组件。 我发现了这样的东西: http://www.jasperpo
我有一个 JToolbar ,其中包含多个 JPanel (需要它,因为我希望每个都有特定的边框)。不幸的是,Look&Feel 管理器无法将 JPanels 识别为属于工具栏,因此 JButtons
我在我的挥杆应用程序中使用 Nimbus 外观。 我设置了 UIDefaults 的主要和次要属性的外观和感觉。 颜色是对的。现在我有一个问题,组件的画家使用颜色,这些颜色是在更新颜色主题之前定义的。
我在 HTML 页面 + JavaScript 上制作了一个自定义下拉菜单。我希望该菜单如下所示: 当点击“Freunde”按钮时,会出现下拉菜单 再次点击按钮时,下拉菜单消失 当鼠标光标离开按钮+下
实际上,外观和感觉是什么意思? 最佳答案 它表示图形用户界面 (GUI) 的外观和行为方式。每个操作系统都有自己典型的外观和感觉。 一开始,Java 有自己的应用程序,但当然大多数人都希望他们的应用程
我正在尝试使用 Nimbus Look and Feel,我不能简单地插入它来替换其他 Look and Feel,因为它在每个组件周围添加了一些外部填充。 所以,我想删除这个填充。这是list可以更
我想要的是使不可编辑的文本区域的背景与其禁用的背景相同。 我知道颜色可以从 UIManager 使用键 TextArea.disabled 获得: DerivedColor(color=214,217
在 JTable (Nimbus L & F) 中编辑数据时,当用户从一个单元格切换到另一个单元格时,哪个单元格具有焦点并不明显。我怎样才能更清楚哪个单元格具有焦点?我知道可以设置许多属性来修改 Ni
我是一名优秀的程序员,十分优秀!