Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-25-2010, 09:55 PM
Member
 
Join Date: Nov 2009
Posts: 34
Rep Power: 0
hannes is on a distinguished road
Default drawing a string vertical
Hey guys,

How can you draw a string vertical with java2d graphics?

thanks, Hannes
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-25-2010, 10:24 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,319
Rep Power: 8
Fubarable is on a distinguished road
Default
What have you tried so far?
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-26-2010, 06:57 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
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.
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
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertical menu Kligham New To Java 11 09-25-2009 05:49 PM
VERTICAL BAR GRAPH in JAVA Robert_85 Java 2D 4 03-08-2009 01:58 PM
Collapsible Vertical Menu ccvid Java Applets 4 01-27-2009 06:40 AM
How to use vertical and horizontal sliders in SWT Java Tip SWT 0 07-02-2008 09:06 PM
what layout to use for vertical alignment? dim_ath AWT / Swing 6 01-20-2008 06:28 PM


All times are GMT +2. The time now is 09:32 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org