Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,592 members, 7,809,146 topics. Date: Friday, 26 April 2024 at 01:17 AM

Rotating A Jlabel Using Netbeans - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Rotating A Jlabel Using Netbeans (5350 Views)

Flexbean: Netbeans Free Alternative To Flexbuilder In 10 Easy Steps! / Is Anything Better Than The Netbeans Ide? / Netbeans Vs Eclipse Vs Jboss (2) (3) (4)

(1) (Reply)

Rotating A Jlabel Using Netbeans by mikkytrio(m): 8:31pm On Jul 02, 2010
Please I am writing an application which when a button is clicked it gets to rotate a jLabel please can I get assistance on what code to use here

private void rotate_15D_ActionPerformed(java.awt.event.ActionEvent evt)
{
// my problem is in here when clicked a jLabel is to rotate by 15 degrees
}
Re: Rotating A Jlabel Using Netbeans by Kobojunkie: 3:12pm On Jul 04, 2010
Check this out http://stackoverflow.com/questions/416897/how-do-i-rotate-a-label-in-c

Though code is in C#, it should be easy for you to read since the two languages are somehow syntatically similar
Re: Rotating A Jlabel Using Netbeans by JFrame: 4:26pm On Jul 07, 2010
Try this Program of mine it will give you great help:


import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

import javax.swing.plaf.basic.*;
import java.awt.geom.*;


// This code uses Graphics2D which is supported only on Java 2

public class Main
{
public static void main(String[] args)
{
JFrame frame = new JFrame("Main"wink;
frame.addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
Window win = e.getWindow();
win.setVisible(false);
win.dispose();
System.exit(0);
}
} );

frame.getContentPane().setLayout( new FlowLayout() );

ImageIcon icon = new ImageIcon( "dukeWave.gif" ) ;
JLabel l = new JLabel( "Rotated anti-clockwise", icon, SwingConstants.LEFT );
l.setUI( new VerticalLabelUI(false) );
l.setBorder( new EtchedBorder() );
frame.getContentPane().add( l );

l = new JLabel( "Rotated Clockwise", icon, SwingConstants.LEFT );
// l.setHorizontalTextPosition( SwingConstants.LEFT );
l.setUI( new VerticalLabelUI(true) );
l.setBorder( new EtchedBorder() );
frame.getContentPane().add( l );
frame.getContentPane().add( new JButton( "Button" ) );
frame.pack();
frame.show();


}
}



class VerticalLabelUI extends BasicLabelUI
{
static {
labelUI = new VerticalLabelUI(false);
}

protected boolean clockwise;
VerticalLabelUI( boolean clockwise )
{
super();
this.clockwise = clockwise;
}


public Dimension getPreferredSize(JComponent c)
{
Dimension dim = super.getPreferredSize(c);
return new Dimension( dim.height, dim.width );
}

private static Rectangle paintIconR = new Rectangle();
private static Rectangle paintTextR = new Rectangle();
private static Rectangle paintViewR = new Rectangle();
private static Insets paintViewInsets = new Insets(0, 0, 0, 0);

public void paint(Graphics g, JComponent c)
{


JLabel label = (JLabel)c;
String text = label.getText();
Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

if ((icon == null) && (text == null)) {
return;
}

FontMetrics fm = g.getFontMetrics();
paintViewInsets = c.getInsets(paintViewInsets);

paintViewR.x = paintViewInsets.left;
paintViewR.y = paintViewInsets.top;

// Use inverted height & width
paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

String clippedText =
layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);

Graphics2D g2 = (Graphics2D) g;
AffineTransform tr = g2.getTransform();
if( clockwise )
{
g2.rotate( Math.PI / 2 );
g2.translate( 0, - c.getWidth() );
}
else
{
g2.rotate( - Math.PI / 2 );
g2.translate( - c.getHeight(), 0 );
}

if (icon != null) {
icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
}

if (text != null) {
int textX = paintTextR.x;
int textY = paintTextR.y + fm.getAscent();

if (label.isEnabled()) {
paintEnabledText(label, g, clippedText, textX, textY);
}
else {
paintDisabledText(label, g, clippedText, textX, textY);
}
}


g2.setTransform( tr );
}
}

(1) (Reply)

Fingerprint Authentication In Vb.net Application / Passing Business Object Between Dal And Bll / Career Opportunities In Nigeria With A Software Engineering Degree?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.