• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

View Files

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
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;
    Bookmark Topic Watch Topic
  • New Topic