tags:

views:

373

answers:

2

i'am using JTransformer class from swinghelper

https://swinghelper.dev.java.net/

when i chose flowlayout there is no problem but if i use null layout i cant see my button on frame

any help would be appreciated.

import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.geom.AffineTransform; import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.EtchedBorder;

import org.jdesktop.swinghelper.transformer.JXTransformer;

public class Main {

/**
 * @param args
 */
private List<JXTransformer> transformers = new ArrayList<JXTransformer>();

private JXTransformer createTransformer(JComponent c) {
 JXTransformer t = new JXTransformer(c);
 transformers.add(t);
 return t;
}

public void fonk() {

 JFrame f = new JFrame();
 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            f.setLayout(new FlowLayout());
            //f.setLayout(null);

 f.setBounds(500,500,500,500);

 JButton b = new JButton("JButton");
 b.setSize(10,10);
 b.setLocation(10,10);
 f.add(createTransformer(b));


 AffineTransform at = new AffineTransform();
 at.rotate(45 * Math.PI / 180);

 for (JXTransformer t : transformers) {
  t.setTransform(at);
 }

 f.show();

}

public static void main(String[] args) {
 // TODO Auto-generated method stub
 new Main().fonk();

}

}

A: 

Your button is probably up and to the left of the upper left corner.

set the rotation angle to 45, -45, 135, -135 degrees in order to determine, around which point it is rotating.

Jens Schauder
+1  A: 

Don't know if it makes a difference but whenever I use the rotate method is just use:

g2.rotate( Math.toRadians( 90 ) );

Or if you want an alternative approach, instead of rotating the entire component you can just use a Rotated Icon

camickr