Posted By:
Ajay_Partoti
Posted On:
Monday, October 3, 2005 03:54 AM
I am using Java platform:jdk 1.4.1 Windows platform: Windows 98se Problem:I am making one application in which i need to display images when i get it from socket.I had used one JScrollPane over JPanel with scrollbars.But when i get the image i stored it into an Image object. such as in my main program screen = Toolkit.getDefaultToolkit().getImage ( "screen.jpg" ); //Draw picture first time it works fine... paintPicture(screen); paintPicture(Image image) {picpnl = new JPanel(); picpnl.setLayout(new BorderLayout())
More>>
I am using
Java platform:jdk 1.4.1
Windows platform: Windows 98se
Problem:I am making one application in which i need to display images when i get
it from socket.I had used one JScrollPane over JPanel with scrollbars.But when i
get the image i stored it into an Image object.
such as in my main program
screen = Toolkit.getDefaultToolkit().getImage ( "screen.jpg" );
//Draw picture first time it works fine...
paintPicture(screen);
paintPicture(Image image)
{picpnl = new JPanel();
picpnl.setLayout(new BorderLayout());
image = Toolkit.getDefaultToolkit( ).getImage(image);
//Is picpnl is unable to display image second time
picpnl.add(new JScrollPane(new ImageComponent(image)),BorderLayout.CENTER);
c.add( picpnl, BorderLayout.CENTER );
picpnl.setVisible(true);
---
---
from my refresh code:
if(image!=null)
image.flush();
Runtime rt = Runtime.getRuntime();
rt.runFinalization();
rt.gc();
image = null;
//is this 2nd time image not properly stored in variable image
image = Toolkit.getDefaultToolkit().createImage( b ,0, b.length );
paintPicture(image);
//go to paintPicture second time doesn't work
The above code works fine for (the first time).But when i try to display a
different socket image (the second time) it doesn't work.
I didn't know what the problem is...
---whether the previous image didn't get erased from RAM or
---the OS is not aware of the current changed image in variable (image) or the
---JScrollPane is unable to redraw it second time.
How can i display one changed image from the socket onto the JScrollPane? (the second time).
Also i want to know if we are using one file with the name "screen.jpg" and at
runtime if i changed that file with another file with the same name. How can i
display that changed file?Is it possible in Java or not.(Is it the limitation of
Java).
I totally get frustated by reading all forums but i didn't get the answer.Please reply me soon with the complete code?
One simillar problem:
creating the label and image icon
String image_dir = new String();
if (type.equals("QUERY") && _Query_Image != null)
{
image_dir = _Query_Image.getDir();
ImageIcon icon = new ImageIcon("C:\Documents and Settings\Administrator\My Documents\My Pictures\01.jpg");
_Image_Label_1 = new JLabel(icon);
JScrollPane pictureScrollPane = new JScrollPane(_Image_Label_1);
pictureScrollPane.setPreferredSize(new Dimension(500,500));
pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));
return pictureScrollPane;
}
in my refresh method
if (_Query_Image != null)
{
_Query_Image_Dir.setText(_Query_Image.getName());
//Change the image icon at runtime it doesn't work.....
_Image_Label_1.setIcon(new ImageIcon(_Query_Image.getDir()));
_Image_Label_1.repaint();
}
<<Less