Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: javaSwings
|
Posted: May 29, 2002 3:31 PM
|
|
OK Giving you the answer for the JLabel may not be a good idea but ... that's what you asked for ! Firstly then, why is it a good idea : With a normal Swing Component you would have to provide him a Renderer & that would do. I mean you just need to chuck a look at the various example on the internet where you could create you CustomCellRendere for a JTable .... Examples : http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/ You may also see on Bruce Eckel's site, but I dunno what's to find there with respect to Swing but his bok is generally speaking excellent !
Back to our problem ! In the case of the JLabel, it has a very different story because the JLabel is really a different animal ! You will have to create you own class RotatableJLable extending the JLabel (There is really no other way, I think) ...
What do you have to implement in the Subclass to do the job is the paintComponent (Graphics g)
... What can you do there ? All what you want ... !
You need to be quiet confirmed in the Grpahics & especially the Graphics2D to do the job as it is needed.
package test.gui;
import javax.swing.*;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Color;
public class RotatableJLabel
extends JLabel
{
RotatableJLabel (String aLabel, int aRotationAngle)
{
super (aLabel);
}
public void paintComponent (Graphics g)
{
// Normally this method should do the automatic redraw upon needs...
// More aftere the w-e when I will be further in the book
// Also with the the World Soccer Cup I will not be there too much !
Graphics2D G2D = (Graphics2D) g;
G2D.draw3DRect ( 0, 0, 0, 0, false);
G2D.setBackground (Color.blue);
System.out.println ("Called");
}
/**
*
*/
public static void main (String[] args)
{
JFrame f = new JFrame (RotatableJLabel.class.getClass ().getName ());
f.setSize (300, 300);
f.setVisible (true);
f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
RotatableJLabel r
= new RotatableJLabel (RotatableJLabel.class.getClass ().getName (), 30);
f.getContentPane ().add ( r );
}
}
Rgds,
Thomas SMETS, SCJP2 - Brussels
Thanks to Gino MARCKX (I hope I spell it right Gino) & Umesh DESAI for the discussions. Also a big tx to John Zukowski for his book :-D
|
|