Hi zusammen,
habe ein kleines Problem mit meinem JScrollContainer:
allerdings wird leider nie ein ScrollContainer erstellt. Weiss jemand wieso??? wäre echt sehr dankbar. danke.
habe ein kleines Problem mit meinem JScrollContainer:
Code:
import java.awt.LayoutManager;
import java.io.File;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
public class PictureReader extends JFrame {
private static final long serialVersionUID = 1L;
private static String[] files;
private static JFrame window;
private static JPanel pane;
private static JLabel picName;
private static JLabel pic;
private static JTextField keywords;
private static JButton ok;
private static JButton cancel;
private static int windowHeight;
private static Vector<JTextField> fields = new Vector<JTextField>();
private static JScrollPane scroller;
public static void read(File testfile, String path) {
files = testfile.list(new ExtensionFilter());
if (files.length > 0) {
initialize(path);
addButtons();
}
}
private static void addButtons() {
ok = new JButton("OK");
ok.setBounds(80, windowHeight - 100, 80, 30);
pane.add(ok);
cancel = new JButton("Cancel");
cancel.setBounds(240, windowHeight - 100, 80, 30);
pane.add(cancel);
}
private static void initialize(String path) {
window = new JFrame();
pane = new JPanel();
pane.setLayout(null);
int picHeight = 40;
for (int i = 0; i < files.length; i++) {
String position = path.concat("/").concat(files[i]);
ImageIcon icon = new ImageIcon(position);
int operator = icon.getIconHeight() / picHeight;
int width = icon.getIconWidth() / operator;
pic = new JLabel(icon);
pic.setBounds(0,(2*i)*picHeight,width,picHeight);
pane.add(pic);
picName = new JLabel(files[i]);
picName.setBounds(width+10, (2*i)*picHeight, new Double(picName.getMinimumSize().getWidth()).intValue(), 20);
pane.add(picName);
keywords = new JTextField();
keywords.setBounds(0, ((2*i)+1)*picHeight, 380, 20);
pane.add(keywords);
fields.add(keywords);
}
windowHeight = ((files.length * 2) * picHeight) + 100;
scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroller.setBounds(0,0,200,200);
scroller.setViewportView(pane);
pane.setBounds(0,0,380,350);
window.getContentPane().add(scroller);
window.setBounds(0,0,400,300);
window.setVisible(true);
}
}
allerdings wird leider nie ein ScrollContainer erstellt. Weiss jemand wieso??? wäre echt sehr dankbar. danke.