The Artima Developer Community
Sponsored Link

Java Answers Forum
javaSwings

3 replies on 1 page. Most recent reply: Jun 2, 2002 1:22 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
sambadamerla

Posts: 1
Nickname: samba
Registered: May, 2002

javaSwings Posted: May 25, 2002 3:27 AM
Reply to this message Reply
Advertisement
how can i palce JLabels each of same Rectanglar dimentions side by side as an arc using degrees or radians


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: javaSwings Posted: May 29, 2002 3:31 PM
Reply to this message Reply
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

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: javaSwings Posted: Jun 2, 2002 4:42 AM
Reply to this message Reply
This currently drives into nothing ...
I am quiete dissappointed of all these & especially myself to not grasp this faster than "that" :-((
I am currently reading this
http://java.sun.com/docs/books/tutorial/2d/display/index.html to get a better grasp but ...

Here below was what I thought would be the latest version of the code but ... it doesn't work :
package test.gui;
 
import javax.swing.*;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.Color;
//import java.lang.Math.PI;
/**
  * @author <a href="mailto:tsmets@altern.org">Thomas SMETS</a>
  */
public class RotatableJLabel
  extends JLabel
{
 
  public static final double DEFAULT_ROTATION_ANGLE = Math.PI / 2;
  public static final double ZEROd = 0d;
  double rotationAngle = 0d;
  
  RotatableJLabel (String aLabel)
  {
    this (aLabel, DEFAULT_ROTATION_ANGLE);    
  }
  
  RotatableJLabel (String aLabel, double aRotationAngle)
  {
    super (aLabel);
    rotationAngle = aRotationAngle;
  }
  
  public void paintComponent (Graphics g)
  {
    Graphics2D G2D = (Graphics2D) g; // So I get a reference to the Graphic
    super.paintComponent (g);        // Request parent to draw it for the sake of simplicity
//    G2D.rotate (this.rotationAngle, this.ZEROd, this.ZEROd);    
    G2D.rotate (rotationAngle);
//    G2D.setBackground (Color.blue);    
//    G2D.setColor (Color.red);
    System.out.println ("Component::paintComponent");
  }
 
// This doesn't help, either
//  public void paint (Graphics g)
//  {
//    Graphics2D G2D = (Graphics2D) g;
//    super.paint (g);    
//    G2D.rotate (rotationAngle);
//    G2D.setBackground (Color.blue);
//    System.out.println ("Component::paint");    
//  }
 
/** 
  *
  */
  public static void main (String[] args)
  {
    JFrame f = new JFrame (RotatableJLabel.class.getName ());
    RotatableJLabel r 
      = new RotatableJLabel (RotatableJLabel.class.getName () );    
    f.getContentPane ().add ( r );    
    f.setSize (300, 300);
    f.setVisible (true);
    f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); 
  }
} // made with www.jcreator.com

Should some one have an idea ... ?
Tx,

Thomas SMETS,
SCJP2 - Brussels

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: javaSwings - keeping on searching ! Posted: Jun 2, 2002 1:22 PM
Reply to this message Reply
I am going over this ...

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=003980

I will provide some working code one of these days :-D

Thomas SMETS,
SCJP2 - Brussels

Flat View: This topic has 3 replies on 1 page
Topic: Difference between System.gc( ) and System.runFinalization( ) methods Previous Topic   Next Topic Topic: Question about variable, methods and constants

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use