Results 1 to 3 of 3
  1. #1
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default drawing a string vertical

    Hey guys,

    How can you draw a string vertical with java2d graphics?

    thanks, Hannes

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    I can think of two ways to do this.
    First make an AffineTransform to rotate and translate the string to the desired position/angle.
    Then you can either
    1 transform the graphics context with the transform, or
    2 create a transformed font using the Font deriveFont method.

    In the case of the graphics approach you will need to save the original transform, use your AffineTransform in the Graphics2D transform method and finally, before exiting the paintComponent method restore the original transform with the setTransform method. This is important because the same graphics context can (will often) be passed along by the Container paint method for drawing borders and child components.
    Java Code:
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        AffineTransform orig = g2.getTransform();
        AffineTransform at = ...
        g2.transform(at);  // concatenates with orig transform
        g2.draw(String(...);
        g2.setTransform(orig);  // resets to original
    }

Similar Threads

  1. Vertical menu
    By Kligham in forum New To Java
    Replies: 13
    Last Post: 07-09-2014, 02:07 PM
  2. VERTICAL BAR GRAPH in JAVA
    By Robert_85 in forum Java 2D
    Replies: 4
    Last Post: 03-08-2009, 12:58 PM
  3. Collapsible Vertical Menu
    By ccvid in forum Java Applets
    Replies: 4
    Last Post: 01-27-2009, 05:40 AM
  4. Replies: 0
    Last Post: 07-02-2008, 08:06 PM
  5. what layout to use for vertical alignment?
    By dim_ath in forum AWT / Swing
    Replies: 6
    Last Post: 01-20-2008, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •