.gif image doesn’t moves on adding it to the JTabbed pane

Let me demonstrate the hole you are digging yourself into You could do… BufferedImage img = ImageIO.read(this.getClass().getResource(“anigif.gif”)); ImageIcon icon = new ImageIcon(img); JLabel label = new JLabel(icon); add(label); Or you could do… Now, this is woefully inadequate and is designed for example purposes only. It does not support disposal methods or optimized Gifs…so you can … Read more

Difference between paint() and paintcomponent()?

Quoting from documentation of paint() method This method actually delegates the work of painting to three protected methods: paintComponent, paintBorder, and paintChildren. … A subclass that just wants to specialize the UI (look and feel) delegate’s paint method should just override paintComponent. It looks like the paint() method actually draws the component, including the border … Read more

How to draw an image over another image?

Another approach that does not require extending components. import javax.swing.*; import java.awt.*; import java.awt.image.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.Random; import java.net.URL; import javax.imageio.ImageIO; public class ImageOnImage { ImageOnImage(final BufferedImage bg, BufferedImage fg) { final BufferedImage scaled = new BufferedImage( fg.getWidth()/2,fg.getHeight()/2,BufferedImage.TYPE_INT_RGB); Graphics g = scaled.getGraphics(); g.drawImage(fg,0,0,scaled.getWidth(),scaled.getHeight(),null); g.dispose(); final int xMax = bg.getWidth()-scaled.getWidth(); final int yMax … Read more

How to draw in JPanel? (Swing/graphics Java)

Note the extra comments. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; class JavaPaintUI extends JFrame { private int tool = 1; int currentX, currentY, oldX, oldY; public JavaPaintUI() { initComponents(); } private void initComponents() { // we want a custom Panel2, not a generic JPanel! jPanel2 = new Panel2(); jPanel2.setBackground(new java.awt.Color(255, 255, 255)); jPanel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); … Read more

the images are not loading

I’m sorry to say this, but there are simply so many things wrong with your code… Lets start with: DON’T override any of the paint methods of a top level container. To start with, none of the top level containers are double buffered. Use light weight components instead of heavy weight components (use JFrame instead … Read more

Stretch a JLabel text

In the approach shown below, the desired text is imaged using TextLayout using a suitably large Font size and scaled to fill the component. There’s a related example here. import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JLabel; /** @see … Read more