Rotating entire JFrame to simulate portrait mode

Hi
I need to rotate the entire jframe into portrait mode.
I cannot use the graphics chip, or linux graphics device manger to change the rotation CW 90 degress - due to hardware design and limitation.
So basically, I have to render the graphics myself, quite easily done with fllowing code at the the top level panel.
protected void paintComponent(Graphics g)
// center of rotation is center of the panel
Graphics2D g2d =(Graphics2D)g;
int xRot = this.getWidth() / 2;
int yRot = this.getHeight() / 2;
g2d.rotate(Math.toRadians(-90), xRot, yRot);
super.paintComponent(g);
This does the job nicely, however the screen is still using landscape co-ordinates, and hence when clicking on the swing components they are in the pre-rotation position.
I have looked and cannot find, is there a simple way to switch a jframe into portrait mode. If not, is there a simple way to intercept the screen coordinates and translate the mouse coordinates to the appropriate JComponent?
thanks in advance
Steve

import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
public class TransformPoints extends JPanel {
    List<PointStore> list = new ArrayList<PointStore>();
    AffineTransform at = new AffineTransform();
    String s = "Hello World";
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        Color color = g2.getColor();
        drawPoints(g2);
        g2.setPaint(color);
        FontRenderContext frc = g2.getFontRenderContext();
        Font font = g2.getFont().deriveFont(36f);
        Graphics2D copy = (Graphics2D)g.create();
        copy.setFont(font);
        LineMetrics lm = font.getLineMetrics(s, frc);
        float height = lm.getAscent() + lm.getDescent();
        float width = (float)font.getStringBounds(s, frc).getWidth();
        int w = getWidth();
        int h = getHeight();
        System.out.printf("w: %d  h: %d%n", w, h);
        float x = (w - width)/2;
        float y = (h - height)/2 + lm.getAscent();
//        copy.rotate(-Math.PI/2, w/2, h/2);
        at.setToRotation(-Math.PI/2, w/2, h/2);
        copy.transform(at);
        copy.drawString(s, x, y);
        // draw some reference lines
        copy.setPaint(Color.pink);
        copy.draw(getBounds());
        copy.drawLine(w/2, 0, w/2, h);
        copy.drawLine(0, h/2, w, h/2);
        copy.dispose();
    private void drawPoints(Graphics2D g2) {
        for(int i = 0; i < list.size(); i++) {
            PointStore store = list.get(i);
            Point p = store.loc;
            g2.setPaint(Color.blue);
            g2.drawString(store.viewLoc, p.x+3, p.y);
            g2.setPaint(Color.red);
            g2.drawString(store.xformLoc, p.x+3, p.y+12);
            g2.fill(new Ellipse2D.Double(p.x-1.5, p.y-1.5, 4, 4));
    public static void main(String[] args) {
        TransformPoints test = new TransformPoints();
        JFrame f = new JFrame("click me");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(test);
        f.setSize(500,300);
        f.setLocation(100,100);
        f.setVisible(true);
        test.addMouseListener(test.ml);
    private MouseListener ml = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            String viewStr = String.format("[%d, %d]", p.x, p.y);
            Point2D.Double xp = getInvertedPoint(p);
            String xfStr = String.format("[%.1f, %.1f]", xp.x, xp.y);
            list.add(new PointStore(p, viewStr, xfStr));
            repaint();
        private Point2D.Double getInvertedPoint(Point2D p) {
            Point2D.Double xp = new Point2D.Double();
            if(at.getDeterminant() != 0) {
                try {
                    at.inverseTransform(p, xp);
                } catch(NoninvertibleTransformException  e) {
                    System.out.println("invert error: " + e.getMessage());
            return xp;
class PointStore {
    Point loc;
    String viewLoc;
    String xformLoc;
    public PointStore(Point p, String view, String xform) {
        loc = p;
        viewLoc = view;
        xformLoc = xform;
}

Similar Messages

  • I use to be able to rotate my iPhone and change the view of an image, Web page, email, and so on, from portrait to landscape, but after update, I cannot. I can only view in portrait mode. Anybody know what's up with that?

    I use to be able to rotate my iPhone and change the view of an image, Web page, email, and so on, from portrait to landscape, but after update, I cannot. I can only view in portrait mode. Anybody know what’s up with that?

    You need to do the basic troubleshooting steps described in the User Guide, Appendix B.
    Restart phone
    Reset phone
    Restore in iTunes using a backup
    Restore in iTunes as new, without using a backup
    If restoring as new doesn't help, there is a hardware failure in the phone that needs evaluation by Apple.

  • My ipad doesn't rotate to portrait mode when reading email why?

    I have set up my mail but my ipad does not rotate to portrait

    My ipad rotates everywhere else but when mail mode.  I can only view mail on landscape, two columns, mail boxes to the left and mail content to the right.  When I flip the pad to portrait it remains the same way and it does not flip as it is supposed to.  No, I do not have the lock button set to lock screen but to mute.  Any ideas?

  • Samsung 244T on Mac OS X - does it rotate to portrait mode?

    I'm thinking of buying a Samsung 24" LCD panel - one of it's more interesting features (for me, at least) is the ability to rotate the panel from landscape to portrait mode - does anyone know if this feature works for sure in MacOS X?
    Dual 2GHz G5   Mac OS X (10.4.7)  

    It doesn't depend on the OS. It depends on the driver for the graphics card. Some Macs do allow rotation and some don't. If you see a rotation option in Display Preferences with your current video card and monitor, then your configuration supports it.

  • Rotate display for portrait mode?

    I'd like to rotate the display orientation on my 15" MBP so that I can read documents in portrait mode while holding the laptop sideways. I found some tips instructing me to hold the option key down while selecting the displays pane in system preferences but that doesn't seem to work.
    I found SMSRotateD which is a little demo that rotates the display using the sudden motion sensor:
    http://www.osxbook.com/software/sms/smsrotated/
    It does successfully rotate the display 90 degrees, but it works erratically and won't stay in one orientation for long. I'd rather do this without the SMS. Can anyone tell me how?

    I do though hesitate to rotate the whole body of the machine. Functioning vertically may not be the best of things to do. At least back 10 years ago, and I don't know if it is true now, shifting the drive from the position it was formatted in relative to gravity to a different one for use without reformatting it can shorten the length of the hard drive. This was the case with the drives on some PowerMac 6500s which were formatted vertically and placed horizontally elsewhere.
    Whether or not you can do that with notebook drives regularly, remains to be seen. I'd say it would be better to get an external display that supports the rotation.

  • How to make a video that "rotate" in portrait mode as some videocast?

    hello,
    long time Apple user, first message in this cool forum.
    my problem is simple:
    -i have a iPhone
    -a car
    -a dock for iPhone in the car in portrait mode (it cant rotate)
    i was wondering if i can add to some of my videos the possibility to rotate like some podcast (Apple quick tips for example) in order to watch a movie in portrait mode when the iPhone is in the dock (and i' am not driving).
    i found a solution that is to import a movie in iMovie, rotate 180° left and then export to iTunes, but this take sooooo many hours even in a new iMac
    can you help me please?
    tks

    I believe I have the same question. I have created some movies in portrait mode. It seems the default for videos on the iPhone is landscape mode, and this makes the 'portrait mode' movies so much smaller. I am looking for a solution so I can play back these movies in portrait mode. We are talking a small number of movies, only 10, but they are important for work and I'd like to be able to show them at the larger portrait size. This would come in very handy at conferences during work related conversations.
    Thanks in advance for any advice.

  • [Lollipop] Turning Auto-rotate off forces portrait mode

    In various situations, I like to use my tablet in landscape mode, but turn auto-rotate off (watching movies/streams while lying down).
    I do this using the pull-down quick menu. After the update to lollipop however, whenever I turn off "Auto-rotate", the button's name will switch to "Portrait" and my tablet (and app) will rotate into portrait mode, even if it was in landscape mode when I pressed the button. I reckon this is done with e-books in mind, but for my purposes this makes this feature useless.
    Is there any way to restore the original behaviour (tablet stays in the orientation it was in when you decide to turn off Auto-rotate)? If there is not currently, I urge you to change it back to the old way (other lollipop tablets seem to have the old behaviour still from what I could gather from friends).

    uliwooly wrote:
    That's the way it's supposed to work 
    Well, that just sounds like an opinion. Do you have any source for that? As I said, my friends' other tablets behave differently.
    Is there anyone from Sony around who can shed some light on this or make inquiries? Or is this a users-help-users-only support forum?
    And @Johnny_dee, please don't hijack threads. The whole discussion now is about a whole other topic. Just open a new topic.
    (maybe some nice moderator could split the topic?)

  • My ipad2 is stuck in portrait mode after iOS 7.0.4 update. How do I get it to rotate again?

    My ipad2 is stuck in portrait mode after iOS 7.0.4 update. How do I get it to rotate again?

    Try following the instructions in this thread:  http://discussions.apple.com/message/23028588#23028588

  • Why don't new imac display driver support rotate into portrait mode

    why don't new 24 in imacs support display rotate into portrait mode? they have ati radeon HD 2600 chipset!

    OK - I figured it out. Apple's 10.4 display driver does not externalize the rotate parameter for the new IMAC alum 24inch display - even though the ATI video card supports rotation.
    However, the SwitchResX utility (search on google) will switch the display into rotate modes 90/180/270. I tried it and it works in 90 degree rotate.
    Once you install SwitchResX, you have to do 2 steps. First, open the SwitchResX control panel and under its Menus tab, further enable its taskbar widget to allow "Display Orientation" settings. Second, then use SwitchresX taskbar widget (now displaying a new "Rotation" parameter setting for Standard - 90 - 180 - 270.
    In addition (obviously ... for safety reasons) you will probably want to attach the device to a VESA standard display mount that allows safe physical rotation of the IMAC. Apple sells for $29 the VESA Mount Adapter Kit for 24-inch iMac. This will allow attachment of the IMAC to a VESA mount. (I am now researching VESA mounts).
    Cheers!

  • Unable to print entire page in portrait mode

    I am using Firefox 5 and running Windows 7. For the last year maybe, I haven' t been able to print from my browser in portrait mode; on a letter-size sheet, the printing fills only the top half of the page and within that, only half of the page. I can print in landscape fine.

    See this: <br />
    http://kb.mozillazine.org/Problems_printing_web_pages

  • How do you edit the template image that appears at the top only in portrait mode?

    I am using a customized version of the iBooks Author template which has the space image. I have replaced the images for the book cover, chapter and section. But I noticed that when you rotate the ipad to view the entire TOC, the original space image is still there. How can I edit the template image that appears at the top of the Table of Contents only when you rotate the ipad in portrait view?

    I just tried w/that template - switched to Portrait mode...tapped once to select that image....cut - gone. Switched to Landscape...not there. Back to portrait...still gone.
    What process did you use?
    Can you repeat your issue with a fresh book?

  • Rotate node for displaying landscape/portrait on handheld device

    The javafx application I am developing will eventually be running on a handheld device with 800x480 resolution. The application will typically be running in portrait mode, but for some features (e.g. displaying charts and tables), it will need to switch to landscape mode to better display the data.
    My question is, is there a straight forward way to operate with nodes that are rotated by multiples of 90 degrees?
    I can rotate the table by calling setRotate(), although this introduces several new issues:
    To resize column widths when rotated, the user has to drag the column dividers left to right (orthogonal to the row of headers), The table still expands its width/height to the size of its parent, although this doesn't work as well when rotated -90 degrees (or other multiples of 90).
    The other constraint is that the chart content is contained in the center of a BorderPane, where the top and bottom of the BorderPane contain toolbars, which prevents rotating the entire scene.
    Here is my SSCCE; please correct me if there are any problems with the code below.
    import javafx.application.Application;
        import javafx.event.ActionEvent;
        import javafx.event.EventHandler;
        import javafx.scene.Scene;
        import javafx.scene.control.Button;
        import javafx.scene.control.TableColumn;
        import javafx.scene.control.TableView;
        import javafx.scene.layout.BorderPane;
        import javafx.scene.layout.Pane;
        import javafx.scene.layout.VBox;
        import javafx.stage.Stage;
        public class TablePanelTrial extends Application {
            BorderPane root = new BorderPane();
            private boolean isRotated=false;
            public static void main(String[] args) {
                launch(args);
            @Override
            public void start(final Stage primaryStage) {
                primaryStage.setTitle("Table Panel Trial");
                final TablePanel tp = new TablePanel();
                Button btnRotate = new Button("Rotate");
                btnRotate.setOnAction(new EventHandler() {
                    @Override
                    public void handle(ActionEvent event) {
                        double r = -90;       
                        if(isRotated){
                            r=0;
                            isRotated = !isRotated;
                        else{
                            r=-90;
                            tp.tv.setMinHeight(200);
                            isRotated = !isRotated;
                        tp.rotate(r);
                root.setTop(btnRotate);
                root.setCenter(tp.getVB());
                primaryStage.setScene(new Scene(root, 480, 800));
                primaryStage.show();
            class TablePanel{
                private VBox vbox = new VBox();
                private TableView tv = new TableView();
                private String[] labelVal = {"Column 1", "Element", "Difference", "File Name", "Report Number"};
                public TablePanel(){
                    TableColumn column1 = new TableColumn(labelVal[0]);
                    TableColumn column2 = new TableColumn(labelVal[1]);
                    TableColumn column3 = new TableColumn(labelVal[2]);
                    TableColumn column4 = new TableColumn(labelVal[3]);
                    TableColumn column5 = new TableColumn(labelVal[4]);
                    tv.getColumns().addAll(column1, column2, column3, column4,column5);
                    vbox.getChildren().add(tv);
                    tv.setPrefHeight(2000);
                public Pane getVB(){
                    return vbox;
                public void rotate(double r){
                    vbox.setRotate(r);
        }

    It will be on an Colibri Tegra ARM board running linux. The application will have a header and footer, with the rotated content taking up the center of a BorderPane, so it might be possible to flip the stage size and somehow then rotate the content in the BorderPane. However, I have not yet found a suitable method to handle the rotating part of the problem. Any ideas?

  • Is there a way to create and edit a video in portrait mode / 9:16 in Premiere Elements 12 or 13. Playback on an iPhone in portrait position.

    I'm editing iPhone app video for posting as the first screen in the Apple app store. Required size for the video is 750:1334, 9:16. I there a way to setup the initial video in portrait mode? Many posts for how to rotate a specific clip, but I need the whole video in portrait position. How to accomplish this? I'm using Windows 7 and Premiere Elements 12 and now 13.

    LaurieFrick
    Thanks for giving this portrait Edit area monitor shape a look.
    I have Windows 7 64 bit and Windows 8.1 64 bit and have done the work using Premiere Elements 12/12.1 on Windows 7 64 bit.
    Here is a step by step
    Find the DSLR [email protected] file
    Local Disk C\Program Files\Adobe\Adobe Premiere Elements 12\Settings\SequencePresets\NTSC\DSLR\1080p\
    And, in that 1080p Folder is the DSLR 1080p30@ 29.97.sqpreset file that you seek.
    1. Copy the
    DSLR 1080p30@ 29.9.sqpreset fileI
    and paste it to the computer desktop in a newly created folder named 1920p.
    2. Open the 1920p Folder and edit the ..sqpreset file in Notepad.
    To do that right click the .sqpreset, and, from the pop up, select Open With and then Notepad.
    3. In the Notepad document, you are going to edit in only 2 places for now, switching 1920 and 1080 to 1080 and 1920 at the top and bottom
    sections of the Notepad document.
    Then go specifically File Menu/Save of the Notepad document and hit Save.
    4. At this point, you have the edited.sqpreset file in the 1920p Folder on the computer desktop.
    (Change the name of the edited .sqpreset file so that it = DSLR [email protected])
    Move the 1920p Folder from there to add it to the 1080p Folder, the location where you found the original .sqpreset file that you edited.
    Close out of there.
    5. Back in the Premiere Elements 12/12.1, manually set the project preset to the new project preset
    6. When you import your 1080 x 1920 9:16 video file into the project and drag it into the Timeline, you should see
    Note that there is no orange line over that Timeline content, indicating that you are seeing
    the best possible preview of the image.
    7. As I wrote before,
    But, here is the hang up. If I render the Timeline content to get the best possible preview at the Edit level, the video in the Edit area monitor
    squeezes in resulting in black borders to the left and right of the video image on screen.
    But, otherwise I found I had no problems editing or exporting, just had to keep away from Timeline rendering for previewing after an edit. Need to find the missing ingredient for 100%.
    I will be writing this up in my blog in a more organized fashion including how I got the project preset description in Change Settings to agree with the changes. Probably I will do that in the morning.
    ATR

  • When I save photos or videos from my iPhone 4S to my PC they are all sideways.  Is there a way to prevent this from happening?  All are taking with the phone in portrait mode.

    When I save photos or videos from my iPhone 4S to my PC they are all sideways.  Is there a way to prevent this from happening?  All are taken with the phone in portrait mode.

    Shot videos ONLY in landscape. For photos choose what's you like. Maybe you have to rotate photos on PC. What's your operating system?

  • How to use a secondary monitor in Portrait mode

    Finally discovered how to do this.  Here is how to use a second monitor in portrait mode:
    Open System Preferences from your iMac dock.
    Click Displays - Click Arrangement - Click Gather Windows - the secondary monitor dialog box opens.
    Click Rotation - Click 90 degrees rotation for PORTRAIT MODE.
    Click CONFIRM on the secondary monitor to keep Portrait mode.
    Select the desired resolution. I chose 1200 x 1920.
    You'll see a dialog box that says, "About to change the display mode."
    Click OKAY.
    Click Confirm. (If it appears. For some resolutions, I did not have to click confirm, most likely because the monitor supports those resolutions.) 
    Then resize the windows of the software you're using.
    Done!

    I too got the same. Both monitors went portrait. Then I unchecked the 'Mirror Display' option in the Arrangment tab of iMac display and voila. Got what I wanted.

Maybe you are looking for

  • Launchd, Startup Item **** - -what am I doing wrong?

    So, I have a startup item which works when I type sudo SystemStarter start MayaFlexlm Works great. Spawns flexlm, a daemon that listens for incoming connections for licensing. Trouble is, it does not automatically start on reboot. I always have to ty

  • Want a better solution for radiobutton code

    I am using radio buttons the code works but it seems very long winded any ideas how I can cut down the code? // code snippet //basicly decare some JRadioButton //set action command currentaccount = new JRadioButton("Current Account"); currentaccount.

  • Trouble viewing Captivate 8 published output.

    Trouble viewing Captivate 8 published output.  I created a course for a client who also wants a video of it.  I published and I can see it on my end, but when I send them the files using DropBox, they can't open the .SWF, the Chrome.HTML, or the AVI

  • Problems downloading Snow Leopard onto my Mac OS X 10.5.8 Macbook

    I recently bought Snow Leopard to download onto my Macbook (Mac OS X Version 10.5.8). When I inserted the disk and it started installing, it wouldn't go past a certain point in the beginning stage of the installation. It didn't move past "59 minutes

  • Maintenance Mode for Synthetic Transactions

    Hi, I'm looking for some guidance on how to apply Maintenance Mode to specific Synthetic Transactions correctly via Orchestrator.  My setup is Orchestrator 2012 R2 (and SCOM 2012 R2) I have an existing runbook which seems to run fine for placing a gr