Trying to rotate whole GUI (contained in a JPanel) by 90 degrees

Hi there,
I'm trying to rotate my GUI by 90 degrees.
I am extending a JPanel, which containes a JTabbedPane, and I want to rotate it by 90 degrees, so that the user can rotate the whole screen and still read the text and get the icons properly displayed.

So far I've seen that I should use AffineTransform with its method getRotateInstance(double theta). But, all the examples I could find and explanations showed me how to rotate single components, like a String for example.

Could anyone give me an example of how to rotate a JPanel with all its components?


In case you want to see my actual main class from my GUI:
[code]
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;

public class TabbedPaneDemo extends JPanel {

      private SpanishPanel spanishPanel ;
      private OpenFilePanel openFilePanel ;
      
      
      
    public TabbedPaneDemo() {
        super(new GridLayout(1, 1));
            
            spanishPanel = new SpanishPanel() ;
            openFilePanel = new OpenFilePanel() ;

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);

            
//        ImageIcon icon = createImageIcon("images/lupa2.gif");
            ImageIcon openIcon = createImageIcon("images/open.gif");
            ImageIcon exitIcon = createImageIcon("images/door.gif");

        JComponent panel1 = makeTextPanel("Panel #1");
        tabbedPane.addTab("", exitIcon, spanishPanel,
                          "nothing");


        JComponent panel3 = makeTextPanel("Panel #3");
        tabbedPane.addTab("", openIcon, openFilePanel,
                          "nothing");



        //Add the tabbed pane to this panel.
        add(tabbedPane);

    }

    protected JComponent makeTextPanel(String text) {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        panel.setLayout(new GridLayout(1, 1));
        panel.add(filler);
        return panel;
    }

    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
//        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("TabbedPaneDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        JComponent newContentPane = new TabbedPaneDemo();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.getContentPane().add(new TabbedPaneDemo(),
                                 BorderLayout.CENTER);

        //Display the window.
        frame.pack();
            frame.setSize(frame.getToolkit().getScreenSize()) ;      
        frame.setVisible(true);
    }

    public static void main(String[] args)
      {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
[/code]
FlashdaddeeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
AFAIK that's not possible. At least if what you're getting at is to see the tabs appearing at the side instead of the top.
Mick BarryJava DeveloperCommented:
> For thread safety, this method should be invoked from the event-dispatching thread.

That method is thread safe, you don't have to execute it from edt.

Where are you performing this rotation?

FlashdaddeeAuthor Commented:
>> AFAIK that's not possible. At least if what you're getting at is to see the tabs appearing at the side instead of the top.

Well, I didn't worry too much about where the tabs appear, since I can change that through the JTabbedPane.BOTTOM variable. But, if it's possible to rotate text and single Components (including images), why wouldn't a JPanel be rotateable (sp?) ?

>> Where are you performing this rotation?

I was thinking about two options, whichever was easier to implement:

a) When the application start, the user chooses a language (English, Spanish or German). I could include an orientation variable as well (horizontal or vertical)

b) Once the application has started, maybe clicking on a button should rotate the whole screen.

Was that what you meant by your question?

Thanks guys
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Mick BarryJava DeveloperCommented:
There is no general way available to rotate a component, and implementing this would be a big job, and would possibly be implemented using a new l&f.
CEHJCommented:
>>But, if it's possible to rotate text and single Components (including images),

To be more precise, images are not Components (at least with a capital 'C'); they are entities in the graphics context, which is where you *can* do transforms. Components (big 'c') map to w/Windows controls or widgets and these have a fixed set of behaviours. When did you last see a window on its side? ;-)
FlashdaddeeAuthor Commented:
ojbects: ok, if it would be that a big job, I'll just leave it by now, and get back to it when I do have more time

CEHJ:  LOL, actually, last time I saw a window on its side was on a Palm device. That's what I'm tryint to achieve but in a Pocket PC (testing on an iPAQ).

Thanks for your replies guys.

Just one question: should I then close the thread and ask for a refund of the points? I mean, since it doesn't seem like it can be done :-(
Mick BarryJava DeveloperCommented:
refunds fine by me
CEHJCommented:
Are you implying that we have not expended any energy on answering your question and therefore deserve no points? ;-)
Mick BarryJava DeveloperCommented:
I don't think points are intended for effort, they are for answers.
CEHJCommented:
I've given an answer
Mick BarryJava DeveloperCommented:
Are you referring to, "thats not possible"?
The question wasn't whether it is possible (which i think it is), it is how to do it.
FlashdaddeeAuthor Commented:
actually you two guys have helped me before

give me a few weeks, and I'll try to implement this idea/task for real

Then there'll be points for everyone ;-)

Thanks



PS: I'll leave the refunds for tomorrow, cause there seems to be a problem with this site, and it's taking minutes (literally) for refreshing the page each time
CEHJCommented:
Personally i would never expect to post a question and deliver no points after people helped me. Since objects seems to think otherwise, i'm sure he'll be pleased to forego his share.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mick BarryJava DeveloperCommented:
> Personally i would never expect to post a question and deliver no points after people helped me.

But you have unlimited points and don't pay for them :-)
CEHJCommented:
That was also the case beforehand
FlashdaddeeAuthor Commented:
Well, you have helped me in a sense, letting me know that it was a difficult task.

But, I haven't been told how to solve it. So, technically, the question hasn't been answered.

If you want I guess I could give some points, but not all the points offered at the beginning?
CEHJCommented:
I'll leave that up to you. At least you won't have to consider objects
Mick BarryJava DeveloperCommented:
> Well, you have helped me in a sense,
> letting me know that it was a difficult task.

It was actually me that let you know that, and I don't expect any points for that information.

Mick BarryJava DeveloperCommented:
I'd suggest asking CS for a refund and let them sort it out.
CEHJCommented:
Well, i've already made my feelings clear above
FlashdaddeeAuthor Commented:
>> Well, i've already made my feelings clear above

What I did was to post at the CS board and ask their opinion.
Are you mad at all? (sorry, but I can't think of any other word in English) If so: sorry.
CEHJCommented:
I don't think that there's any point in my explaining any more. I made my position clear at Date: 11/25/2003 01:35PM PST
FlashdaddeeAuthor Commented:
OK, you have my paid points.
CEHJCommented:
Thank you. Now a bit more on the question. I'd go further than objects and say that i'm 99% certain this is impossible on normal Windows. I'd be surprised if this is any different on a PDA. You say you saw one on its side. Are you sure it was a normal window with animated buttons (and that the rotation was not due to a physical rotation of the casework)? You can certainly make something that *looks* like a window that is merely a graphic with 'hotspots'. You *could* argue that *any* window is just a graphic with hotspots, and in a way that's true, but don't forget it has behaviours, animation, geometry that is inherent in the OS itself. Java layers on top of the OS's windowing environment so you couldn't really have a Java window on its side unless you can have a normal window on its side.
FlashdaddeeAuthor Commented:
Well, there are Palm devices that allow you to rotate the whole thing by clicking on a key. Since PDAs use such "weird" screen resolutions, sometimes it's more convinient to get the PDA on its side.

I usually don't have Microsoft Windows in mind, since I'm thinking only about Java on any device.

Fernando
CEHJCommented:
>>
Well, there are Palm devices that allow you to rotate the whole thing by clicking on a key.
>>

So i believe - hence my comment. That's no more rotating the window programmatically than holding your head on one side is it? ;-)
FlashdaddeeAuthor Commented:
Hmm, I'm sorry, but I don't really understand what you mean











after almost five years living in the UK, my English is not perfect yet :-(  
CEHJCommented:
Well i'm guessing that what's going on is NOT the programmatic rotation of the GUI - but I could be wrong (I've never seen this happen)
FlashdaddeeAuthor Commented:
Well, I guess it could be done through the programm as well. That's what I'd like to achive

I'll try after January.
Mick BarryJava DeveloperCommented:
> I'd go further than objects and say that i'm 99% certain this is impossible on normal Windows.

Well I've actually developed a side-wise component for a client, so you are definitely wrong there.

So I'm interested to know which comment of your you are so adamant deserved the points?
CEHJCommented:
>>
Well I've actually developed a side-wise component for a client, so you are definitely wrong there.
>>

Well I'll believe it when I see it. You'll convince me if you can show a vertical menu bar.
CEHJCommented:
Actually, I meant title bar.
Mick BarryJava DeveloperCommented:
> You'll convince me if you can show a vertical menu bar.

Read the comments above again.

Just because you believe it is true doesn't make it so :)
Mick BarryJava DeveloperCommented:
> Well I'll believe it when I see it.

So what are you actually saying here, that I'm lying??
CEHJCommented:
>>So what are you actually saying here, that I'm lying??

No, i'm just saying that creating a sideways component is not a problem, but i don't believe you can rotate the whole window. If you had the component in a window, its title bar would still be horizontal.
Mick BarryJava DeveloperCommented:
> No, i'm just saying that creating a sideways component is not a problem,

So which of your comments then are you so adamant was the correct answer to the question being asked??

> If you had the component in a window, its title bar would still be horizontal.

Even that can be resolved.
CEHJCommented:
>>Even that can be resolved

With its functioning, animated buttons bound to a windowing system peer? I'm quite willing to eat my words if you can show me a working example.
FlashdaddeeAuthor Commented:
>> I'm quite willing to eat my words if you can show me a working example.

If he shows a working example, then he should get the points :)
CEHJCommented:
If he does, i'll give you your points back and him the same number. Conditions are: show a frame on its side with normal working buttons
Mick BarryJava DeveloperCommented:
> So which of your comments then are you so adamant was the correct answer to the question being asked??

you still haven't answered my question? Can't be too hard can it?
Mick BarryJava DeveloperCommented:
> then he should get the points :)

I already explained I don't want the points and why.
Your question was not answered so you should have got a refund.
CEHJCommented:
>>you still haven't answered my question? Can't be too hard can it?

The correct answer is that i'm pretty certain that it can't be done. But i'm willing and waiting to be proved incorrect
Mick BarryJava DeveloperCommented:
> The correct answer is that i'm pretty certain that it can't be done.

Which contradicts what you said above:

> i'm just saying that creating a sideways component is not a problem

And just because you don't believe it can be done does not make it so.

Mick BarryJava DeveloperCommented:
Flashdaddee,

When you have another q feel free to email me and I'll try and help you to make up for the points you have wrongly lost here.

And for the benfits of others reading this question what  Flashdaddee has asked is possible using the technique I suggested earlier.
CEHJCommented:
The best way you can help him get the points is to show us a window on its side
Mick BarryJava DeveloperCommented:
> The best way you can help him get the points

him get the points ????

> show us a window on its side

that wasn't even the question asked.

enough's been said here, you've got your precious points so lets not muddy up this PAQ any further.
Mick BarryJava DeveloperCommented:
And for the benefit of others reading this question the approach I suggested for achieving this is in one of my earlier posts.
CEHJCommented:
>>him get the points ????

Get the points back

If Flashdaddee meant he's quite content to see no transform on the main window, but only on the components it contains, leaving the window unaltered, then I've misunderstood.

At any rate, if you can show even that, I'll refund the points.
Mick BarryJava DeveloperCommented:
> then I've misunderstood.

well the question never mentioned windows
and a window is also achievable anyway.

>  I'll refund the points.

how big of you.
CEHJCommented:
>>and a window is also achievable anyway.


I'm afraid nobody's going to be impressed with mere assertions. A link to an example would be different ...
Mick BarryJava DeveloperCommented:
That was discussed earlier to the satisfaction of Flashdaddee, so I'm not sure why you keep bringing it up, or it fact what it has to do with you as it is Flashdaddee question not yours.
CEHJCommented:
The point is simple: a negative cannot be proved, but a positive can. Since you assert the positive with such authority, it's up to you to prove it. Otherwise you have the authority of a man who says he's Napoleon Bonaparte
Mick BarryJava DeveloperCommented:
> a negative cannot be proved

ie. you are saying you don't know how to do, which I wouldn't think deserved even mentioning let alone being accepted as an answer.

I have explained why a proof isn't required which you seem to be ignoring. And I'm not demanding that my comments be accepted as an answer anyway.
Mick BarryJava DeveloperCommented:
If you get any clients wanting custom components implement though, feel free to send them my way :)
FlashdaddeeAuthor Commented:
>> show us a window on its side

> that wasn't even the question asked.

That's right, I never asked to rotate a Window, all I asked was to rotate a JPanel with its contents as well.

>> A request for deletion or PAQ has been made.  If no response or you feel this is in error, comment.  IF NO OBJECTION, I or another Moderator will handle this question in three days.  If you, the questioner have not answered comments from experts concerning your question, we will ask that you address those before action is taken.

In the previous paragraph, it states IF NO OBJECTION, so that's why I gave the points, because there was one objection.
I don't think it was fair, but I didn't make any rules, I just paid for some points.

Still, I have learned something: next time, I will state on in my question exactly what I am looking for, and will say that the points will be given only to certain answers.

objects: thanks for the offer ;-)
CEHJCommented:
>>That's right, I never asked to rotate a Window, all I asked was to rotate a JPanel with its contents as well.


Well, see my comments above. If objects can show you how to do that, I'll give you your points back.
Mick BarryJava DeveloperCommented:
Flashdaddee>  IF NO OBJECTION, I or another Moderator will handle this question in three days

If there are objections then a moderator can make a decision if required.

Flashdaddee> next time, I will state on in my question exactly what I am looking for

I don't think you're question was that unclear. You never mentioned windows, CEHJ did.

CEHJ> If objects can show you how to do that,

Thats irrelevant and I'm not going to repeat my answer to that comment again.

You've got your precious points so you can stop posting here now.
CEHJCommented:
>>Thats irrelevant ...

Not quite sure, if someone is trying to do something:

>>I'm trying to rotate my GUI by 90 degrees.

showing *how* to do it can be irrelevant.

>>Could anyone give me an example of how to rotate a JPanel with all its components?

The answer seems now to be, yes, objects could, but he won't. This is rather at variance with his earlier statement:

>>
There is no general way available to rotate a component, and implementing this would be a big job, and would possibly be implemented using a new l&f.
>>

>>You never mentioned windows, CEHJ did

Yes, because practically speaking, controlling part of the gui without being able to control what is containing it (the window) seems to be of limited practical use

But this is academic anyway, as it's been stated with some authority that complete rotation, including the window, is possible anyway, although so far supporting evidence has been conspicuous by its absence
Mick BarryJava DeveloperCommented:
running around in circles and still twisting the question I see. Well, you keep demanding points for your "I don't know how" answers if that makes you happy :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.