How to Rotate Text 90 Degree?

I tried to rotate text so that it reads from bottom to
top of the screen (vertically). How to do it?
I tried w/ Graphics2D and AffineTransform class but fail.
Here is my code:
AffineTransform af = new AffineTransform(0.0, 1.0, 1.0,
0.0, 0.0, 0.0);
Graphics2D newg = (Graphics2D) g;
g.setTransform(af);
g.drawString("Rotated Text", 70.0f, 70.0f);
Anybody do text rotation please post reply.
Thanks!

Turns out the bug still persists, and I post new Q on
this forum. Please check it out.
But here is the my entire code, if you would like to see
and try:
import javax.swing.DefaultCellEditor;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
public class CompJFC
static JFrame frame1;
static final int cWidth = 500;
static final int cHeight = 500;
Object[] ctable = {"Usage Graph for Users",
"Usage Graph for Servers",
"Usage Graph for Appliances",
"Top 20 Users (Last 30 Days)",
"Top 20 Users (Last 60 Days)",
"Top 20 Users (Last 90 Days)"};
JComboBox ccombo = new JComboBox(ctable);
JPanel panel1, panel2, panel3;
JCanvas canvas;
public class JCanvas extends JComponent
Insets insideBorder;
JCanvas()
super();
JCanvas(int cWidth, int cHeight)
insideBorder = new Insets(cHeight-150, 50, 50, cWidth-60);
public void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
AffineTransform af1 = g2.getTransform();
int xp = insideBorder.left-35;
int yp = insideBorder.top-100;
AffineTransform af2 =
AffineTransform.getRotateInstance(Math.toRadians(270), xp, yp);
g2.setTransform(af2);
g2.drawString("Number of Online Users", xp, yp);
g2.setTransform(af1);
public void AddComp()
panel1 = new JPanel();
panel1.add(ccombo);
ccombo.addItemListener(new ItemListener()
public void itemStateChanged(ItemEvent evt)
String selected;
panel2.remove(canvas);
canvas = new JCanvas(cWidth, cHeight);
panel2.add(canvas, BorderLayout.CENTER);
panel2.repaint();
frame1.setVisible(true);
canvas = new JCanvas(cWidth, cHeight);
panel2 = new JPanel(new BorderLayout());
panel2.add(canvas, BorderLayout.CENTER);
panel3 = new JPanel(new BorderLayout());
panel3.add(panel1, BorderLayout.NORTH);
panel3.add(panel2, BorderLayout.CENTER);
JTabbedPane tpane = new JTabbedPane();
tpane.addTab("Chart", panel3);
frame1.getContentPane().add(tpane);
public static void main(String args[])
CompJFC jc = new CompJFC();
frame1 = new JFrame("Swing GUI Exercise");
frame1.setSize(cWidth, cHeight);
frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
frame1.getContentPane().setLayout(new BorderLayout());
jc.AddComp();
frame1.setVisible(true);

Similar Messages

  • How to rotate text

    I was told to restate my number's problem as I want to rotate text within a single cell. This is for grade book so the column label can be hidden along with other data.

    ohsster,
    I was also excited by iWorks, and I was planning to adopt it and try to wean myself from Office even before Numbers was announced. I figured I'd just use the Tables within Pages to do my spreadsheet functions, since all the same calculations are available there. After a month of working in iWork, it's obvious that it would be premature to un-install Office for Mac, but I'm still determined to make the switch and I believe that Apple will address the serious issues, like the speed problem, in short order. So, I'm still excited about being closer to shaking the Microsoft dependency.
    Regarding your application, I don't know how large and complicated your design is, but I encourage you to try my suggestion just to get a feel for working with references that span sheets and tables. This, to me, is much easier in Numbers than in Excel. I tried cross-sheet referencing in Excel years ago and found it too complicated, but in Numbers it is as simple as pie. You can build your second table in the same sheet as your first table if you want to keep things close together for that phase, and then just drag the new table to a new sheet when you're done with it. To make a cell in the destination table mirror the entry in the source table, simply type an = sign in the destination cell and then click on the source cell. To replicate the reference in the first destination cell across the first row, highlight that cell and drag the fill handle across the row. Then, with the filled row highlighted, drag the fill handle down the sheet to populate as many rows as you need. This whole process takes only a few seconds. Now you have a copy of the source table that can be independently formatted, labeled and printed after you move it to it's own sheet. This is the Numbers equivalent of setting a Print Area in Excel, except on steroids.
    I hope you don't give up!
    Jerry

  • How to rotate text together with a Rectangle2D?

    Hi forum
    I hope you can help me out here. See the follow code example. I have a Rectangle2D, in which some text is rendered. What I'm trying to do here is the following: rotate the Rectangle2D - no problem here - but the text should follow - ie. still be rendered the same way inside the Rectangle2D after the rotation transform is applied. The theta value is just an example - it should work the same for any theta value.
    Ie - after the rotation, the text is drawn with the first letter just right of the left angle of the rotated Rectangle2D, just as with the original drawn text.
    I'm aware, that the key to doing this is to figure out what point to rotate the text around. I would believe, that the correct answer would be the same point as the Rectangle2D, but that doesn't seem to work, as you can see, if you run the code. Can someone help me to get this to work correctly?
    Any help would be appreciated! Thanks in advance!
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class ScaleToFill extends JPanel {
        Rectangle2D.Float rect = new Rectangle2D.Float(200,200,220,35);
        float theta = 1.1748778437843f;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setPaint(Color.blue);
            Font font = g2.getFont().deriveFont(18f);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            String s = "This text should be rotated";
            float width = (float)font.getStringBounds(s, frc).getWidth();
            LineMetrics lm = font.getLineMetrics(s, frc);
            float height = lm.getAscent() + lm.getDescent();
            // Draw text as-is.
            // Scale text into rect.
            float xScale = rect.width / width;
            float yScale = rect.height / height;
            // Locate string origin.
            double x = rect.x;
            double y = rect.y + rect.height - yScale*lm.getDescent();
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            float scale;
            if (xScale > yScale)
              scale = yScale;
            else
              scale = xScale;
            at.scale(scale, scale);
            AffineTransform rotator = new AffineTransform();
            rotator.rotate(theta, rect.getX()+(rect.getWidth() / 2), rect.getY()+(rect.getHeight() / 2) );
            GeneralPath rect2 = new GeneralPath(rotator.createTransformedShape(rect));
            g2.draw(rect);
            g2.draw(rect2);
            g2.setFont(font.deriveFont(at));
            g2.setPaint(Color.red);
            g2.drawString(s, 0, 0);
            at.rotate(theta, rect.getX()+(rect.getWidth() / 2), rect.getY()+(rect.getHeight() / 2) );
            g2.draw(rect2);
            Font rotateFont = font.deriveFont(rotator);
            g2.setFont(rotateFont);
            g2.setPaint(Color.red);
            g2.drawString(s, 0, 0);
            // Check scaled string bounds.
        public static void main(String[] args) {
            ScaleToFill test = new ScaleToFill();
            test.setPreferredSize(new Dimension(800,600));
            JFrame f = new JFrame();
            f.getContentPane().add(test);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setVisible(true);
            System.out.println(new Color(0,255,0,0));
    }

    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class STF extends JPanel {
        Rectangle2D.Float rect = new Rectangle2D.Float(200,200,220,35);
    //    float theta = 1.1748778437843f;
        double theta = Math.PI/6;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                                RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
                                RenderingHints.VALUE_STROKE_PURE);
            g2.setPaint(Color.blue);
            Font font = g2.getFont().deriveFont(18f);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            String s = "This text should be rotated";
            float width = (float)font.getStringBounds(s, frc).getWidth();
            LineMetrics lm = font.getLineMetrics(s, frc);
            float height = lm.getAscent() + lm.getDescent();
            // Scale text into rect.
            float xScale = rect.width / width;
            float yScale = rect.height / height;
            float scale = (xScale > yScale) ? yScale : xScale;
            // Locate string origin.
            double x = rect.x;
            double y = rect.y + (rect.height + scale*height)/2 - scale*lm.getDescent();
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            at.scale(scale, scale);
            AffineTransform rotator = new AffineTransform();
            rotator.rotate(theta, rect.getCenterX(), rect.getCenterY());
            GeneralPath rect2 = new GeneralPath(rotator.createTransformedShape(rect));
            // Draw with no rotation.
            g2.draw(rect);
            g2.setPaint(Color.red);
            g2.setFont(font.deriveFont(at));
            g2.drawString(s, 0, 0);
            // Rotate once.
            g2.setPaint(Color.blue);
            g2.draw(rect2);
            rotator.concatenate(at);
            g2.setFont(font.deriveFont(rotator));
            g2.setPaint(Color.red);
            g2.drawString(s, 0, 0);
            // Rotate again.
            rotator.setToIdentity();
            rotator.rotate(2*theta, rect.getCenterX(), rect.getCenterY());
            rect2 = new GeneralPath(rotator.createTransformedShape(rect));
            g2.setPaint(Color.blue);
            g2.draw(rect2);
            rotator.concatenate(at);
            g2.setFont(font.deriveFont(rotator));
            g2.setPaint(Color.red);
            g2.drawString(s, 0, 0);
            // Check scaled string bounds.
            // this was handled by the fractional metrics rendering hint
        public static void main(String[] args) {
            STF test = new STF();
            test.setPreferredSize(new Dimension(800,600));
            JFrame f = new JFrame();
            f.getContentPane().add(test);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setVisible(true);
    }

  • How do I rotate text within a table Pages 4.3?

    Does anyone know how to rotate text within a cell in a Pages 4.3 table?

    You would have to use a floating text box over the cell. Make sure text wrap is turned off.

  • In Preview, when I add text annotations to my PDF (lecture note slides), they look fine until I close it and reopen it, and then they are rotated 90 degrees. How do I fix this and keep it from happening again?

    In Preview, when I add text annotations to my PDF (lecture note slides), they look fine until I close it and reopen it, and then they are rotated 90 degrees. How do I fix this and keep it from happening again?

    I have the same problem with lectures slides.
    Furthermore, sometimes the text box, when doube-clicking, turns  the text into a one-liner. Causing the text box to sometimes get 3. times wider than the pdf itself.
    tcrother wrote:
    ... then when it rotates the text isn't visible and I'm stuck clicking on random parts of my lecture slides hoping the text box will come back. ...
    By pressing [cmd + I] the Inspector opens up and clicking on the rightmost tab 'Annotations' you should be able find those Annotations again. I do this regularly to find the empty annotations I accidentally create while clicking through slides.

  • Rotating text without embedding fonts - how?

    No doubt same or similar question was asked and most likely answered but I could not
    find anything that would match...
    I want to draw column headers of my ADG vertically. So, I need rotate column text 90 degree
    and adjust position.
    Is it true that it can be achieved with embedded font only? If it is true how can it be done for
    Unicode code, which includes ranges for Japanese, Chinese, etc characters. The size of
    swf is going to be huge. Several sites like this
    http://www.forestandthetrees.com/2009/06/29/rotating-text-without-embedding-fonts/
    claims that they have a solution for the problem without embedding fonts.
    Note: I am still using Flex 3.3 SDK with no TLF. By the way, do TLF libraries work with
    3.3 SDK.?
    Thanks in advance

    Draw your text onto a bitmap image (or take an ImageSnapshot of a Label), then rotate the image.

  • How to rotate a Text Field?

    Is there anyone who knows how to rotate a Text Field? I just need to move some degrees (for example: clockwise).
    Thanks in advance for any help you can provide

    You can onlt rotate it in 90 degree imcrements ...this is controlled on the
    layout tab next to the anchor setting.
    Paul

  • How to rotate a text in the adobe reader for mobile ios ?

    how to rotate a text in the adobe reader for mobile ios ?

    There's no rotate command to rotate the document. Instead, rotate the iPad. If it doesn't rotate, turn off the Rotation Lock switch on the side of your iPad.

  • In pages, how can I rotate text ?

    In pages, how can I rotate text ?

    The text needs to be in a TextBox which you can create from the ToolBar and the that can be rotated by control clicking near the top right corner of TextBox and dragging it around.
    Alternatively click on the TextBox > Inspector > Metric > Rotate: enter value.
    Peter
    Greetings from hot, sweaty and beautiful Broome

  • Anyone know how to rotate imported file 90 degrees in iMovie?

    anyone know how to rotate imported file 90 degrees in iMovie?
    i am watching myself laying down giving a talk, and need it to be vertical!
    thanks...

    Use the Rotate, Crop, Ken Burns Tool on the Middle Toolbar.

  • Portrait pics rotate 90 degrees when emailed/texted.

    When sharing pictures from my G3, pictures that i take as a portrait are shown rotated 90 degrees or in landscape mode.  They show correctly on my G3 even when i rotate the phone.  However, pictures I take with the phone on it's side(landscape) display correctly when I open them up on a pc/text.  I can't see a setting to change on the phone to correct this.  I've had 3 G2's in the last four weeks and none of them had this issue and couldn't find answer with Google search.  TIA!

    Luckily, after uploading a photo on Facebook, Facebook gives you the option of rotating the photo. Just click the 90º arrow next to the photo.
    My problem WAS uploading the photos to another online photo album (gardenguides.com-- a gardening blog). Even tho' I'd fix the orientation in Preview and save them with the correct orientation, when I uploaded them to gardenguides.com, they came out upside-down or sideways. I worked around it by first saving them in the correct orientation in Preview, then uploading them to Photobucket (a free online photo storage site). For some reason, Photobucket DOES keep them oriented exactly the way I have them saved.
    THEN, once they are uploaded to Photobucket, I looked at one at a time, control+click and scrolled to the option of "Save this image." (In other words, I downloaded the photos I had just uploaded to Photobucket.) Then I took THOSE saved images and uploaded THEM to my gardenguides.com blog, where they came out right-side-up. It was a hassle, but it worked. Thankfully it was only 5 photos that I took incorrectly-- someone on here said to be sure from now on to hold your iPhone with the Home button on the right when taking pictures.

  • Need to rotate text 90 degrees in Numbers...any hints?

    Need to rotate text 90 degrees in Numbers...any hints?

    If you mean rotate text in a cell then this discussion may help with ideas to coerce Numbers to do what you want when it does not have the capability:
    https://discussions.apple.com/message/17454065#17454065

  • Video clips imported from an iPhone into iMovie ver 6 are rotated 90 degrees; how can I fix this or avoid it?

    Video clips imported from an iPhone into iMovie ver 6 are rotated 90 degrees; how can I fix this or avoid it?

    iMovie works best with uncompressed audio. If your track is MP3 or AAC, you may get better results by converting your track to the AIFF format and then using that in iMovie.
    You can do this in iTunes. Go to iTunes/Preferences and click the General button. On the General page, click the Import Settings button. Choose IMPORT USING: AIFF ENCODER.
    (note: remember what you changed it from so you can change it back later, before you import another CD)
    Now, in iTunes, select your track. Then click FILE/CREATE NEW VERSION/AIFF VERSION.

  • How do you rotate text in numbers

    I'm trying to rotate the text in header row by 90 degrees.  Is this possible in Numbers?

    You cannot rotate text in any cell of a table.  There are a variety of technoques to work around this limitation:
    1) rotate a text box with the header text in it:
    2) copy the desired header text (which is rotated) then open Preview and create a new document from the clipboard.  Then use the rectangular selection tool to surround one word, then copy, then paste that into one of the cells in you header:
    Create new Preview doc from the clipboard contents:
    Now copy words out of preview using the rectangular selection tool:
    copy.
    now select the cell where you want this text:
    There are some other ways (which you can find by searching this forum).
    Hope these help

  • How do you rotate text

    I am looking to rotate text 90 degrees. I cant seem to find this basic function in numbers.

    Hi Bru,
    Text rotation is possible in Shapes and Text Boxes, but not in Tables. You can put a rotated image into a table cell, but you won't be able to use the text in the image in any functions.
    Here's the way I prefer for placing rotated text into a Table Cell.
    Insert > Text Box
    Type text into box
    Size the text and set the box dimensions to your liking - not critical on the size, but the proportions are important
    Click once on the box to select the object, not the text inside
    Rotate the object in the direction you desire
    Command-C to copy the object to the Clipboard
    Switch to Preview.app
    Command-N to make a PDF of the Clipboard Content
    Command-C to place the PDF file on the clipboard
    Switch back to Numbers
    Command-V to paste it to the cell where you want it
    It takes less time to do it than to tell about it.
    Jerry
    I made an error in my sequence in the original post - now corrected.

Maybe you are looking for

  • Auto-complete for the email addresses in the mail app is not working

    Hi, could somebody kindly help, please? I have just got a new iphone 5s after my old 5 got broken. When I got the new 5s one I had to restore everything from the back-up copy I had on my ipad or in my icloud, whatever. The problem is that in the stan

  • Printing from PDF is slightly larger

    I placed an image on an 8.5x11 piece of paper and saved it as a PDF. Once it was printed directly from Acrobat the image was printed slightly larger than when I print directly from Photoshop. Why is this and is there any way I can fix it? By the way

  • I opened my iphone 5c and got a few problems

    i opened it and when i did i pulled to hard and the cables attached to the screen plugged into the rest of the phone ripped and now the screen doesnt show anything and touch doesnt work. though i found out how to fix this and am getting a new screen

  • How to Verify Junk Filter Learning?

    Hi, With some helpful posts on this board, I setup Junk Mail filtering in 10.4 a few months ago. While it appears that everything is running fine, the system doesn't seem to learn much about what it should or shouldn't tag as spam. I'm using Spamtrai

  • J1IS in subcontracting with full payment of excise duty

    hi Can u tell me please In subcontracting with full payment of excise duty I have created PO,sent material to stock provided to vendor (541).while creating outgoing excise invoice with referance to material doc.(MATD) i am getting following error. GL