I'm trying to place a textbox on top of a .png in a panel. I attempt to accomplish this by using JLayeredPane(). However, instead of displaying the .png file with a textbox superimposed on it, java merely displays solely the textbox. :c-blink:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class LoadImageApp extends JFrame
{
public static void main(String[] args)
{
JFrame f = new JFrame("Frame Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField testField = new JTextField(12);
testField.setLocation(50, 50);
BufferedImage img = null;
try
{
img = ImageIO.read(new File(
"/Users/joshuamedlock/Java/asdf_MotionToContinue.png"));
} catch (Exception e){}
JLabel picLabel = new JLabel(new ImageIcon(img));
JPanel contentPane = new JPanel(new BorderLayout());
f.setContentPane(new JScrollPane(contentPane));
contentPane.add(new JLayeredPane());
contentPane.add(picLabel, null, new Integer(0));
contentPane.add(testField, null, new Integer(1));
f.pack();
f.setVisible(true);
}
}


Sign In
Create Account

Back to top










