• Post Reply Bookmark Topic Watch Topic
  • New Topic

View Files  RSS feed

Manoj Paul
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends...

I have a textbox where i am writing the complete path of an image to show an image in the right side of the window...

What should i do so that the system take the path from the input textbox and display the image file in the right side of the window?....

Please help me out..
Thank you
shyam shridhar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class TestImageFrame {
private JFrame mainFrame = null;

private JTextField imagePathTF = null;

private JButton loadImageButton = null;

private MyCanvas imageCanvas = null;

private JPanel northPanel = null;

public TestImageFrame() {
mainFrame = new JFrame();
mainFrame.setLayout(new BorderLayout());
northPanel = new JPanel();
imagePathTF = new JTextField(20);
loadImageButton = new JButton("Load Image");
imageCanvas = new MyCanvas();

loadImageButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
File f = new File(imagePathTF.getText());
BufferedImage image = ImageIO.read(f);
} catch (Exception e) {


mainFrame.add(northPanel, BorderLayout.NORTH);
mainFrame.add(imageCanvas, BorderLayout.CENTER);
mainFrame.setSize(500, 600);


public static void main(String[] ar) {
new TestImageFrame();

class MyCanvas extends Canvas {
private BufferedImage image = null;

public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);

public void setImage(BufferedImage bufferedImage) {
image = bufferedImage;
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!