java swing TabbedPane位置tabheaders从右下到左 [英] java swing TabbedPane position tabheaders bottom right to left

查看:36
本文介绍了java swing TabbedPane位置tabheaders从右下到左的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能将选项卡式窗格放置在右下角,我想将容器制作成彼此上方的容器,一个标签从右上到左(没问题/默认),另一个标签在底部(到目前为止很好)从右到左开始.我想象的设计是:

I wonder if there is any possibility to position a Tabbed pane to the bottom right, I want to make to containers above each other, the one with the tablabels at the top right to left (no problem/default), and the other one with the tablabels at bottom (so far so good) starting from right to left. The design I imagine is:

| tab display                                 |
| tab display                                 |
| tab display                                 |
-----------------------------------------------
_________________________  | tab top | another|
| Bottom Tab| Second Tab|______________________
|                                              |

好吧,我的 ascy 绘图能力有限,但我希望你能看懂.有什么方法可以将布局管理器添加到选项卡式窗格以布局选项卡标签吗?我在哪里可以找到这样的例子?Goodling 建议将菜单栏与 CardLayout 结合用于选项卡式窗格.但是我不知道如何绘制菜单栏,使其看起来像选项卡.(我只是查看了用于自定义绘图的 Swingtrail,但它只是继续讨论一般可能性,此外,如果我这样做,我会失去样式功能.我现在唯一能想到的就是使用没有内容的选项卡式窗格,并且让它通过事件监听器控制另一个带有卡片布局的容器.

well, my ascy drawing capabilities are limited but I hope you get the picture. Is there any way, in wich I can add a layout manager to a tabbed pane to layout the tablabels? Where can I find an example of such? Goodling suggested to just use a menubar in combination with a CardLayout for the tabbed panes. However I have no clue how to draw a menubar so that it looks like tabs. (I just peeked into the swingtrail for custom drawing but it just goes on about the general possibility, besides If I do so I loose the styling capabilities. The only thing I can think off right now is to use a tabbed pane with no content and make it controll another container with a card layout via eventlisteners.

有什么建议吗?

P.S.:我必须用 java 1.6 来实现解决方案

P.S.: I have to implement the solution with java 1.6

推荐答案

在这种情况下,您可以为 JTabbedPane 设置 ComponentOrientation

In this case you can to set ComponentOrientation for JTabbedPane

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 TabbedPane位置tabheaders从右下到左的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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