Answers for "jlabel flip java swing example"

0

jlabel flip java swing example

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class RotateJLabelTest extends JFrame {
   public RotateJLabelTest() {
      setTitle("Rotate JLabel");
      JLabel label = new RotateLabel("TutorialsPoint");
      add(label, BorderLayout.CENTER);
      setSize(400, 300);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLocationRelativeTo(null);
      setVisible(true);
   }
   private class RotateLabel extends JLabel {
      public RotateLabel(String text) {
         super(text);
         Font font = new Font("Verdana", Font.ITALIC, 10);
         FontMetrics metrics = new FontMetrics(font){};
         Rectangle2D bounds = metrics.getStringBounds(text, null);
         setBounds(0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
      }
      @Override
      public void paintComponent(Graphics g) {
         Graphics2D gx = (Graphics2D) g;
         gx.rotate(0.6, getX() + getWidth()/2, getY() + getHeight()/2);
         super.paintComponent(g);
      }
   }
   public static void main(String[] args) {
      new RotateJLabelTest();
   }
}
Posted by: Guest on October-16-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language