Solved

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

Posted on 2003-11-25
60
2,277 Views
Last Modified: 2013-11-23
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]
0
Comment
Question by:Flashdaddee
  • 24
  • 24
  • 11
60 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9820122
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9820221
> 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?

0
 

Author Comment

by:Flashdaddee
ID: 9820404
>> 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
0
 
LVL 92

Expert Comment

by:objects
ID: 9820478
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9820517
>>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? ;-)
0
 

Author Comment

by:Flashdaddee
ID: 9820608
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 :-(
0
 
LVL 92

Expert Comment

by:objects
ID: 9820625
refunds fine by me
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9820632
Are you implying that we have not expended any energy on answering your question and therefore deserve no points? ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 9820641
I don't think points are intended for effort, they are for answers.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9820661
I've given an answer
0
 
LVL 92

Expert Comment

by:objects
ID: 9820702
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.
0
 

Author Comment

by:Flashdaddee
ID: 9820710
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
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 9820750
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9820789
> 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 :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9820806
That was also the case beforehand
0
 

Author Comment

by:Flashdaddee
ID: 9820855
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?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9820871
I'll leave that up to you. At least you won't have to consider objects
0
 
LVL 92

Expert Comment

by:objects
ID: 9820886
> 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.

0
 
LVL 92

Expert Comment

by:objects
ID: 9820986
I'd suggest asking CS for a refund and let them sort it out.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9838547
Well, i've already made my feelings clear above
0
 

Author Comment

by:Flashdaddee
ID: 9838605
>> 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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9838631
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
0
 

Author Comment

by:Flashdaddee
ID: 9838647
OK, you have my paid points.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9838681
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.
0
 

Author Comment

by:Flashdaddee
ID: 9839467
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9839485
>>
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? ;-)
0
 

Author Comment

by:Flashdaddee
ID: 9839503
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 :-(  
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9839527
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)
0
 

Author Comment

by:Flashdaddee
ID: 9839539
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.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 92

Expert Comment

by:objects
ID: 9839717
> 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?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9839765
>>
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9839780
Actually, I meant title bar.
0
 
LVL 92

Expert Comment

by:objects
ID: 9839845
> 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 :)
0
 
LVL 92

Expert Comment

by:objects
ID: 9839852
> Well I'll believe it when I see it.

So what are you actually saying here, that I'm lying??
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9839888
>>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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9839959
> 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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9842178
>>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.
0
 

Author Comment

by:Flashdaddee
ID: 9842725
>> 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 :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9842740
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
0
 
LVL 92

Expert Comment

by:objects
ID: 9843329
> 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?
0
 
LVL 92

Expert Comment

by:objects
ID: 9843338
> 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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9844045
>>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
0
 
LVL 92

Expert Comment

by:objects
ID: 9844078
> 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.

0
 
LVL 92

Expert Comment

by:objects
ID: 9844087
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9844094
The best way you can help him get the points is to show us a window on its side
0
 
LVL 92

Expert Comment

by:objects
ID: 9844104
> 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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9844127
And for the benefit of others reading this question the approach I suggested for achieving this is in one of my earlier posts.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9844128
>>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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9844136
> 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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9844150
>>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 ...
0
 
LVL 92

Expert Comment

by:objects
ID: 9844167
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9844197
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
0
 
LVL 92

Expert Comment

by:objects
ID: 9844231
> 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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9844233
If you get any clients wanting custom components implement though, feel free to send them my way :)
0
 

Author Comment

by:Flashdaddee
ID: 9844920
>> 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 ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9845070
>>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.
0
 
LVL 92

Expert Comment

by:objects
ID: 9846483
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9849406
>>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
0
 
LVL 92

Expert Comment

by:objects
ID: 9852493
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 :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now