Convert text content to Image

The Graphics 2D API should be capable of achieving what you need. It has some complex text handling capabilities as well. import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class TextToGraphics { public static void main(String[] args) { String text = “Hello”; /* Because … Read more

Using addMouseListener() and paintComponent() for JPanel

This is not an immediate answer to your question, but knowing (or at least suspecting) what it is that you wish to offer (a simple paint program), I suggest starting with this approach based around a BufferedImage as the painting surface.. import java.awt.*; import java.awt.RenderingHints.Key; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.HashMap; … Read more

java drag and drop

The major issues I can see are you are mixing two different API’s. You’re using both the low level D’n’D API and the newer “component D’n’D” API. Personally, the newer API annoys me, so I tend to avoid it. I can’t see why you need to transfer the label, when it would be better to … Read more

What is java.awt.Component.getName() and setName() used for?

Component.setName(..) is used in the JDK mostly by the look and feel implementation classes to set ID-like strings for each component, e.g. BasicOptionPaneUI might call it on a button component to set its name to “OptionPane.button”. The getName() is used in toString() methods, when setting the names of child components inside a Composite/parent Component and … Read more