如何在 Java 中创建垂直选项卡?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6390215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:42:23  来源:igfitidea点击:

How to create vertical tabs in Java?

javaswingtabsvertical-alignmentjtabbedpane

提问by bancer

I would like to get the effect like if JTabbedPane would be turned 90 degrees counterclockwise (only tabs but not the content inside tabs). What is the best way to implement that in Java?

我想获得 JTabbedPane 逆时针旋转 90 度的效果(只有选项卡,而不是选项卡内的内容)。在 Java 中实现它的最佳方法是什么?

采纳答案by jzd

In this solution:

在这个解决方案中:

http://oreilly.com/pub/a/mac/2002/03/22/vertical_text.html

http://oreilly.com/pub/a/mac/2002/03/22/vertical_text.html

The text was painted vertically and tried as an icon on the tab. This way you don't have to modify JTabbedPane you just use a custom Icon in the tab.

文本被垂直绘制并尝试作为选项卡上的图标。这样您就不必修改 JTabbedPane,您只需在选项卡中使用自定义图标。

Of course you would also have to specify the tab placement to be on the Left.

当然,您还必须指定选项卡放置在左侧。

回答by trashgod

As an alternative, consider JToolBarwith orientationset to VERTICALin a BorderLayout, EASTor WEST. It's fairly easy rotate textin the button's Icon.

作为替代方案,考虑JToolBarorientation设置为VERTICAL一个BorderLayoutEASTWEST。这也很容易旋转文本按钮的Icon

回答by Sergii Zagriichuk

You can try setTabPlacement(SwingConstants.LEFT)or this component

你可以试试setTabPlacement(SwingConstants.LEFT)或者这个组件

回答by MikeColfs

You could try and extend the tabpane class, in the overloaded paint method, get the graphics object, say g2dis the argument of the overloaded paint method:

您可以尝试扩展 tabpane 类,在重载的paint方法中,获取图形对象,比如说g2d是重载paint方法的参数:

super(g2d.rotate(Pi/2));

as a starter

作为首发