Source Code : Getting the Shape from the Outline of Text
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Getting the Shape from the Outline of Text
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main extends JPanel {
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.draw(getTextShape(g2d, "asdf", new Font("", 1, 30)));
}
public Shape getTextShape(Graphics2D g2d, String str, Font font) {
FontRenderContext frc = g2d.getFontRenderContext();
TextLayout tl = new TextLayout(str, font, frc);
return tl.getOutline(null);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Basic Shapes");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Main());
frame.setSize(350, 250);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Thank with us