当标签放置设置为左侧时JTabbedpane标题的垂直方向 [英] Vertical orientation of JTabbedPane titles when the tab placement is set to LEFT

查看:38
本文介绍了当标签放置设置为左侧时JTabbedpane标题的垂直方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下图所示,Java 文本是水平的.我想要做的是获得 JTabbedPane 标题的垂直方向.

As you can see from the image below, the Java text is horizontal. What I would like to do is get a vertical orientation of the JTabbedPane Titles.

在谷歌搜索时,我发现唯一的方法是添加额外的库.但我想知道这是否可以在没有任何额外库的情况下完成?

While googling, I found that the only way is to add extra library. But I was wondering if this can be done without any extra library?

我希望 Title1Title2 是垂直方向而不是水平方向

I would like for Title1 and Title2 to be vertically oriented and not horizontally

推荐答案

你必须使用 Html 语法,对于禁用的 Tab 的任何更改也是

you have to use Html syntax, for any changes to the disabled Tab too

tabbedPane.addTab("<html>T<br>i<br>t<br>t<br>l<br>e<br>1</html>", panel1);  

编辑

SSCCE 关于 Html 文本格式和对齐的问题

SSCCE for question about Html text formatting and alignment

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

/**
 *
 * @author korbel
 */
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.setEnabledAt(2, false);
        /*int comp = tabbedPane.getComponentCount();
        for (Component sc : tabbedPane.getComponents()) {
        if (sc instanceof javax.swing.JLabel) {
        JLabel lbl = (JLabel) sc;
        lbl.setForeground(Color.red);
        }
        if (sc instanceof javax.swing.JPanel) {
        JPanel pnl = (JPanel) sc;
        pnl.setName(pnl.getName());
        }
        if (sc instanceof javax.swing.JTextField) {
        JTextField txt = (JTextField) sc;
        txt.setForeground(Color.blue);
        txt.setDisabledTextColor(Color.red);
        }
        }
        UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
        UIManager.put("TabbedPane.highlight", new Color(255, 0, 0));
        UIManager.put("TabbedPane.lightHighlight", new Color(0, 255, 0));
        UIManager.put("TabbedPane.darkShadow", new Color(0, 255, 0));
        UIManager.put("TabbedPane.shadow",new Color(0, 0, 255));
        UIManager.put("TabbedPane.light" ,  new Color(0, 255, 0));
        UIManager.put("TabbedPane.foreground", new Color(0, 0, 0));
        UIManager.put("JTabbedPane.font", new Font("Dialog", Font.ITALIC, 12));
        UIManager.put("TabbedPane.selected", new Color(255, 0, 0));
        UIManager.put("disable", new Color(255, 0, 0));
        UIManager.put("TabbedPane.selectHighlight" , new Color(0, 0, 0));
        UIManager.put("TabbedPane.background",  new Color(0, 0, 0));
        SwingUtilities.updateComponentTreeUI(tabbedPane);*/
        tabbedPane.setTitleAt(2, "<html><font color="
                + (tabbedPane.isEnabledAt(2) ? "black" : "red") + ">"
                + tabbedPane.getTitleAt(2) + "</font></html>");
        tabbedPane.setTabPlacement(JTabbedPane.LEFT);
    }

    public static void main(String args[]) {
        TestTabbedPane frame = new TestTabbedPane();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}

这篇关于当标签放置设置为左侧时JTabbedpane标题的垂直方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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