Rotate a Swing JLabel?

I got it to work now with a little help of a coworker. Basically I now have a field that indicates whether to swap height/width which is only active for the time when the original JLabel does its painting.

I got it to work now with a little help of a coworker. Basically I now have a field that indicates whether to swap height/width which is only active for the time when the original JLabel does its painting. Private boolean needsRotate; @Override public Dimension getSize() { if (!needsRotate) { return super.getSize(); } Dimension size = super.getSize(); switch (getDirection()) { case VERTICAL_DOWN: case VERTICAL_UP: return new Dimension(size.

Height, size. Width); default: return super.getSize(); } } @Override public int getHeight() { return getSize(). Height; } @Override public int getWidth() { return getSize().

Width; } @Override protected void paintComponent(Graphics g) { Graphics2D gr = (Graphics2D) g.create(); switch (getDirection()) { case VERTICAL_UP: gr. Translate(0, getSize().getHeight()); gr. Transform(AffineTransform.

GetQuadrantRotateInstance(-1)); break; case VERTICAL_DOWN: gr. Transform(AffineTransform. GetQuadrantRotateInstance(1)); gr.

Translate(0, -getSize().getWidth()); break; default: } needsRotate = true; super. PaintComponent(gr); needsRotate = false; }.

– Mike Caron Jan 26 '10 at 20:10 See hypftier. De/dump/RotatedLabel. Java – the license mentioned is a pretty liberal one, modeled after the BSD (though the license text is only available in German so far).

– Joey Jan 26 '10 at 23:38.

I think it is off because you are translating about the wrong point. The size of the object depends on what container you have this in, so while your preferred size might be what you want, your actual size isn't? If you have this label in the CENTER of a BorderLayout, the size is always the full size of the container (minus north+south height, minus east+west width) so don't you have to translate about the actual size, not preferred size?

Hmm ... not ... quite. Placement is a little off because the label's vertical (now horizontal) alignment is centered, but the size is now exactly square. Could it be that the superclass doesn't care about my overridden getPreferredSize method and thus draws itself not in respect to my boundaries?

– Joey Mar 7 '09 at 8:22.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions