Help!! JScrollPane dilemma!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help!! JScrollPane dilemma!!

sandratzsandratz Posts: 18Member
Hi! I'm trying to write a program that displays images along with info about them onto a JScrollPane. The info
is read in from a file and stored in the Photo object. I've checked the Photo object, the data is stored correctly. The problem is when I click Show All on the menubar, only date and time appears on the scrollpane! Pls help. Here are the codes for PhotoGUI class and PhotoGUIDriver class:

[code]
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class PhotoGUI extends JFrame {

private JMenuBar mbar;
private JMenuItem exit,showAll;

FileMenuItemListener filelistener = new FileMenuItemListener();
PhotoMenuItemListener photolistener = new PhotoMenuItemListener();


Container c= getContentPane();



PhotoGUI(String title) {
super("Photo Info Program");
c.setLayout(new BorderLayout());

mbar=new JMenuBar();

c.setLayout(new BorderLayout());


JMenu file = new JMenu("File");
JMenu photo = new JMenu("Photo");


exit = new JMenuItem("Exit");
showAll = new JMenuItem("Show All");

exit.addActionListener(filelistener);
showAll.addActionListener(photolistener);

increasingDateTime.addActionListener(exposurelistener);
decreasingDateTime.addActionListener(exposurelistener);

file.add(exit);
photo.add(showAll);

mbar.add(file);
mbar.add(photo);


c.add(mbar,BorderLayout.NORTH);

}

class PaneDisplay extends JPanel {
//display image and information about it onto a panel

private JLabel image,latAndLonglabel,keyword,datetime;
private JPanel jpane = new JPanel();


String keywords,latitudeAndLongitude,dateAndTime;

PaneDisplay (Photo p) {


jpane.setLayout(new BorderLayout());

keywords = p.getKeywords();
latitudeAndLongitude= (p.getLatitude() + " " + p.getLongitude());
dateAndTime=(p.getDay()+ "/" + p.getMonth()+"/"+p.getYear()+" "+
p.getHours()+":"+p.getMinutes()+":"+p.getSeconds());


image = new JLabel(new ImageIcon(p.getImagePath()),JLabel.CENTER);
latAndLonglabel=new JLabel(latitudeAndLongitude,JLabel.CENTER);
datetime=new JLabel(dateAndTime,JLabel.CENTER);
keyword=new JLabel(keywords,JLabel.CENTER);

jpane.add(image);
jpane.add(keyword);
jpane.add(latAndLonglabel);
jpane.add(datetime);
add(jpane);
c.add(new JScrollPane(jpane),BorderLayout.CENTER);

}
}


class FileMenuItemListener implements ActionListener {
private JFrame parent;

public void FileMenuItemListener(){
this.parent=parent;
}

public void actionPerformed(ActionEvent e){

System.exit(0);
}


}

class PhotoMenuItemListener implements ActionListener {
private JFrame parent;
private JPanel photopanel;
private JScrollPane jpane;
PhotoFileReader pfr;


Photo[] photos;

public void PhotoMenuItemListener(JFrame parent){
this.parent=parent;

}

public void actionPerformed(ActionEvent e){
photopanel= new JPanel();
photopanel.setLayout(new BorderLayout());

//read in info from photo.txt
try {
pfr = new PhotoFileReader();
}
catch(IOException io){
System.out.println("An IOException has occured!");
}

JMenuItem item = (JMenuItem)e.getSource();
if (item.getLabel()=="Show All") {

for (int i=0; i<pfr.numOfPhotos(); i++){
//display all available photos onto the panel
photos=pfr.displayAllPhotos();

PaneDisplay pane = new PaneDisplay(photos[i]);

photopanel.add(pane);
jpane=new JScrollPane(photopanel);

c.validate();



}



}
}
}


}
[/code]

[code]
//PhotoGUIDriver.java
//Driver for the main program, PhotoGUI

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class PhotoGUIDriver extends JFrame{


PhotoGUIDriver(){


addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
dispose();
System.exit(0);
}
});
}

public static void main(String args[]) {

PhotoGUI pgui = new PhotoGUI("Photo Info Program");

pgui.setBounds(140,70,400,300);
pgui.show();
}
}
[/code]

Sign In or Register to comment.