Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4273484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:43:09+00:00 2026-05-21T07:43:09+00:00

in my Java application, I have a JTabbedPane and a synth look&feel. The l&f

  • 0

in my Java application, I have a JTabbedPane and a synth look&feel. The l&f is defined by a xml file. This works very fine for me.

Now the challenge: I want the text in the tabs of the JTabbedPane to be written vertically, not horizontally. For this, I subclassed the SynthGraphicsUtils and overwrote the method paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex). This works also.

Now the problem: the text in the different tabs is shown vertically, but the size of every tab seems to be misscalculated. The tabs are not separated correctly. Unfortunatly I’m not allowed to post images… The tabs overlay each other.

I don’t know how to fix this problem 🙁 Here’s my code:

SwingTest.java

public SwingTest(JFrame owner) {

    super(null);

    setOpaque(true);
    setSize(WIDTH, HEIGHT);
    owner.setSize(WIDTH, HEIGHT);

    JTabbedPane pane = new JTabbedPane(JTabbedPane.LEFT);
    pane.setName("MyPane");
    pane.setSize(WIDTH, HEIGHT);

    // Add a tab
    JPanel p1 = new JPanel();
    p1.setSize(300, 300);

    JPanel p2 = new JPanel();
    p2.setSize(500, 500);

    JPanel p3 = new JPanel();
    p3.setSize(300, 300);

    p3.add(new JLabel("HALLO"));

    JPanel p4 = new JPanel();
    p4.setSize(300, 300);

    JButton roundedButton = new JButton("Halloi Button");
    roundedButton.setName("roundedButton");

    p2.add(roundedButton);

    pane.addTab(EFFORT_CARD, p1);
    pane.addTab(EMOTION_CARD, p2);
    pane.addTab(COMFORT_CARD, p3);      
    pane.addTab(DRIVING_CARD, p4);

    add(pane);

    pane.updateUI();

laf.xml

<!-- 
TABNAVIGATION
 -->
<style id="tabNavigationStyle">
    <!-- Angabe ist wichtig, da die Hintergrundfarben sonst nicht angezeigt
    werden. -->
    <!-- <object id="verticalTextWriterClass" class="VerticalTextWriter" />
    <painter method="text" idref="verticalTextWriterClass"/> -->
    <opaque value="TRUE" />
    <state>
        <font name="Verdana" size="12" />
        <color value="WHITE" type="BACKGROUND" />
        <color value="BLACK" type="FOREGROUND" />
        <color value="BLUE" type="TEXT_FOREGROUND" />
        <object id="myGraphicsUtils" class="MySynthGraphicsUtils" />
        <graphicsUtils idref="myGraphicsUtils" />
    </state>
    <!-- Fuer den Zustand "SELECTED" einen anderen Style definieren. -->
    <state value="SELECTED">
        <!-- Auf weiter oben definierte Farbe beziehen. -->
        <color value="WHITE" type="BACKGROUND" />
        <color idref="magentaForegroundColor" type="TEXT_FOREGROUND" />
    </state>
    <state value="FOCUSED">
        <!-- Auf weiter oben definierte Farbe beziehen. -->
        <color value="WHITE" type="BACKGROUND" />
        <color idref="magentaForegroundColor" type="TEXT_FOREGROUND" />
    </state>
    <state value="PRESSED">
        <!-- Auf weiter oben definierte Farbe beziehen. -->
        <color value="WHITE" type="BACKGROUND" />
        <color idref="magentaForegroundColor" type="TEXT_FOREGROUND" />
    </state>
</style>
<!-- Den Style fuer die Tabnavigation an die Tabnavigation mit dem Namen (type="name")
"MyPane" binden. Der Name wird in Java ueber component.setName() festgelegt. -->
<bind style="tabNavigationStyle" type="region" key="TabbedPaneTab" />

MySynthGraphicsUtils.java

public class MySynthGraphicsUtils extends SynthGraphicsUtils {
public void paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex) {

    Graphics2D g2 = (Graphics2D) g;

    System.out.println(ss.getComponent().getClass().getName());

    Object oldAAValue = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

    g2.setFont(ss.getStyle().getFont(ss));
    AffineTransform tx = new AffineTransform();
    tx.rotate(90 * Math.PI / 180, x, y);
    g2.setTransform(tx);

    g2.drawString(text, x, y);

    // get metrics from the graphics
    FontMetrics metrics = g2.getFontMetrics(ss.getStyle().getFont(ss));
    // get the height of a line of text in this font and render context
    int hgt = metrics.getHeight();
    // get the advance of my text in this font and render context
    int adv = metrics.stringWidth(text);
    // calculate the size of a box to hold the text with some padding.
    Dimension size = new Dimension(adv + 2, hgt + 2);

    //g2.setClip(0, 0, size.width, size.height);

    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldAAValue);
}

}

Thank you very much!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:43:10+00:00Added an answer on May 21, 2026 at 7:43 am

    As a workaround, I use an image border with an sourceInset on the Left side to seperate Tabs. I make the image the same colour as the background of the app:

            <state>
                    <opaque value="true"/>
                    <color value="black" type="BACKGROUND" />
                    <color value="white" type="TEXT_FOREGROUND" />
                    <imagePainter method="tabbedPaneTabBorder" path="relative/path/to/white_border.png"
                 sourceInsets="0 1 0 0" paintCenter="false"/>
                    <insets top="3" bottom="3" right="3" left="3"/>
            </state>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Java application I have some copy-constructors like this public MyClass(MyClass src) {
I would like to create extend a Java Swing application to have a look
I have a running java GUI application right now in a single class file,
I have created a java application which has a JTabbedPane that contains three JPanels.
I have made a java application and have packed it into an executable jar
In a Java web application I have a recurring message load of type A
I am developing a Java Desktop Application but have some confusions in choosing a
I need to write a standalone Java application which will have a embedded HTTP
I am working on the I18n of our java application and we have decided
I have a Java application that launches another java application. The launcher has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.