Hallo,
kann mir jemand sagen warum meine JMenuBar einfach nicht angezeigt wird? Hab schon alles mögliche probiert ???:L
kann mir jemand sagen warum meine JMenuBar einfach nicht angezeigt wird? Hab schon alles mögliche probiert ???:L
Java:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.io.File;
import java.io.FileFilter;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class PhotoApp extends JFrame implements ListSelectionListener {
private static final long serialVersionUID = 1L;
// Anfang Attribute
private File[] files;
private File directory;
JMenuBar menuBar;
JMenu menu, submenu;
JMenuItem menuItem;
JRadioButtonMenuItem rbMenuItem;
JCheckBoxMenuItem cbMenuItem;
private JLabel picture;
private JScrollPane listScrollPane;
private JScrollPane pictureScrollPane;
private JSplitPane splitPane;
private JList PhotoList;
// Ende Attribute
public PhotoApp() {
this.directory = new File("photos/");
if (!directory.isDirectory()) {
System.err.println("Dies ist kein Verzeichnis: " + directory);
}
this.setTitle("Photo App");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setSize(900, 500);
this.setLayout(new BorderLayout());
menuBar = new JMenuBar();
files = readDirectory();
PhotoList = new JList(files);
listScrollPane = new JScrollPane(PhotoList);
pictureScrollPane = new JScrollPane();
picture = new JLabel();
pictureScrollPane = new JScrollPane(picture);
Dimension minimumSize = new Dimension(100, 50);
listScrollPane.setMinimumSize(minimumSize);
pictureScrollPane.setMinimumSize(minimumSize);
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane,
pictureScrollPane);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(200);
menu = new JMenu("A Menu");
menuBar.add(menu, BorderLayout.NORTH);
PhotoList.setSelectedIndex(0);
PhotoList
.setBorder(BorderFactory.createTitledBorder("Your Pictures: "));
PhotoList.setBackground(Color.lightGray);
PhotoList.addListSelectionListener(this);
JScrollPane scroll = new JScrollPane(splitPane);
this.add(scroll, BorderLayout.CENTER);
this.validate();
this.setVisible(true);
// Anfang Komponenten
// Ende Komponenten
}
// Anfang Methoden
private File[] readDirectory() {
File[] files = directory.listFiles(new FileFilter() {
@Override
public boolean accept(File currentFile) {
return currentFile.getName().toLowerCase().endsWith(".jpg");
}
});
return files;
}
public static void main(String[] args) {
new PhotoApp();
}
@Override
public void valueChanged(ListSelectionEvent e) {
JList list = (JList) e.getSource();
ImageIcon icon = new ImageIcon(list.getModel()
.getElementAt(list.getSelectedIndex()).toString());
picture.setIcon(icon);
picture.setHorizontalAlignment(SwingConstants.CENTER);
picture.setVerticalAlignment(SwingConstants.CENTER);
pictureScrollPane.updateUI();
}
// Ende Methoden
}