我想知道是否有可能将选项卡式 Pane 放置在右下角, 我想制作一个彼此上方的容器,一个标签标签位于从右到左的顶部(没问题/默认),另一个标签标签位于底部(到目前为止还不错),从右到左。 我想象的设计是:
| tab display |
| tab display |
| tab display |
-----------------------------------------------
_________________________ | tab top | another|
| Bottom Tab| Second Tab|______________________
| |
好吧,我的 ascy 绘图能力有限,但我希望你能明白。 有什么方法可以将布局管理器添加到选项卡式 Pane 来布局选项卡标签吗?我在哪里可以找到这样的例子? Goodling 建议仅将菜单栏与选项卡式 Pane 的 CardLayout 结合使用。但是我不知道如何绘制菜单栏,使其看起来像选项卡。 (我刚刚查看了用于自定义绘图的 swingtrail,但它只是继续讨论一般可能性,此外,如果我这样做,我会失去样式功能。我现在唯一能想到的就是使用没有内容的选项卡式 Pane ,并且让它通过事件监听器控制另一个具有卡片布局的容器。
有什么建议吗?
P.S.:我必须使用 java 1.6 来实现该解决方案
最佳答案
在这种情况下,您可以为 JTabbedPane 设置 ComponentOrientation
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
public class TestTabbedPane extends JFrame {
private static final long serialVersionUID = 1L;
private JTabbedPane tabbedPane;
public TestTabbedPane() {
tabbedPane = new JTabbedPane();
tabbedPane.setPreferredSize(new Dimension(300, 200));
getContentPane().add(tabbedPane);
JPanel panel = new JPanel();
tabbedPane.add(panel, "null");
JTextField one = new JTextField("one");
tabbedPane.add(one, "one");
JTextField two = new JTextField("two");
//tabbedPane.add(two, "<html> T<br>i<br>t<br>t<br>l<br>e <br> 1 </html>");
tabbedPane.add(two, "<html> Tittle 1 </html>");
tabbedPane.setEnabledAt(2, false);
tabbedPane.setTitleAt(2, "<html><font color="
+ (tabbedPane.isEnabledAt(2) ? "black" : "red") + ">"
+ tabbedPane.getTitleAt(2) + "</font></html>");
tabbedPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
}
public static void main(String args[]) {
TestTabbedPane frame = new TestTabbedPane();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
关于java swing JTabbedPane 位置选项卡标题从右下到左,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10909007/