Results 1 to 3 of 3
Thread: drawing a string vertical
- 01-25-2010, 08:55 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 54
- Rep Power
- 0
-
- 01-26-2010, 05:57 AM #3
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
-
Vertical menu
By Kligham in forum New To JavaReplies: 11Last Post: 09-25-2009, 04:49 PM -
VERTICAL BAR GRAPH in JAVA
By Robert_85 in forum Java 2DReplies: 4Last Post: 03-08-2009, 12:58 PM -
Collapsible Vertical Menu
By ccvid in forum Java AppletsReplies: 4Last Post: 01-27-2009, 05:40 AM -
How to use vertical and horizontal sliders in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM -
what layout to use for vertical alignment?
By dim_ath in forum AWT / SwingReplies: 6Last Post: 01-20-2008, 05:28 PM


LinkBack URL
About LinkBacks

Bookmarks