public class JSplitPaneTest extends JFrame implements ActionListener
{
private Vector v_titles;
private Vector v_artist;
private Vector v_genre;
private JLabel rightBottom;
private JList list;
private JList l_titles;
private DefaultListModel m_titles;
private JList l_artist;
private DefaultListModel m_artist;
private JList l_genre;
private DefaultListModel m_genre;
private JSplitPane splitPane;
private JSplitPane splitPaneLeft;
private JSplitPane splitPaneRight;
private JLabel leftBottom;
private JPanel top;
private JLabel topLeft;
private JLabel topMiddle;
private JLabel topRight;
private JScrollPane scroll_topLeft;
private JScrollPane scroll_topMiddle;
private JScrollPane scroll_topRight;
private JScrollPane scroll_rightBottom;
private JMenuBar menuBar;
private JMenu menuFile;
private JMenuItem menuAddFolder;
private JMenuItem menuFileExit;
private static final long serialVersionUID = 01;
public JSplitPaneTest()
{
initComponents();
}
private void initComponents()
{
this.setTitle("JSplitPaneProject_Achatschitz Patrick[3961]");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
menuBar = new JMenuBar();
menuFile = new JMenu( "File" );
menuFileExit = new JMenuItem("Exit");
menuFileExit.addActionListener(this);
menuFile.add(menuFileExit);
menuAddFolder = new JMenuItem("Add Folder");
menuAddFolder.addActionListener(this);
menuFile.add(menuAddFolder);
menuBar.add( menuFile );
this.setJMenuBar(menuBar);
//Create the list of images and put it in a scroll pane.
list = new JList();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane listScrollPane = new JScrollPane(list);
Dimension minimumSize = new Dimension(100, 50);
listScrollPane.setMinimumSize(minimumSize);
m_titles = new DefaultListModel();
l_titles = new JList(m_titles);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_artist = new DefaultListModel();
l_artist = new JList(m_artist);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_genre = new DefaultListModel();
l_genre = new JList(m_genre);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//Set up the picture label and put it in a scroll pane.
scroll_rightBottom = new JScrollPane(rightBottom);
scroll_rightBottom.setMinimumSize(minimumSize);
top = new JPanel(new GridLayout(1,3));
top.setMinimumSize(minimumSize);
l_titles = new JList();
Border border = LineBorder.createGrayLineBorder();
l_titles.setBorder(border);
scroll_topLeft = new JScrollPane(l_titles);
l_artist = new JList();
l_artist.setBorder(border);
scroll_topMiddle = new JScrollPane(l_artist);
l_genre = new JList();
l_genre.setBorder(border);
scroll_topRight = new JScrollPane(l_genre);
top.add(scroll_topLeft);
top.add(scroll_topMiddle);
top.add(scroll_topRight);
leftBottom = new JLabel("Area Left Bottom!!");
leftBottom.setMinimumSize(minimumSize);
leftBottom.setHorizontalAlignment(SwingConstants.CENTER);
splitPaneLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, leftBottom);
splitPaneLeft.setDividerLocation(400);
splitPaneRight = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, scroll_rightBottom);
splitPaneRight.setDividerLocation(320);
//Create a split pane with the two scroll panes in it.
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitPaneLeft, splitPaneRight);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(200);
//Provide a preferred size for the split pane.
splitPane.setPreferredSize(new Dimension(1000, 600));
this.getContentPane().add(splitPane);
this.pack();
}
//actionPerformed method for the Exit menu entry
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("Exit"))
{
System.exit(1);
}
else if(e.getActionCommand().equals("Add Folder"))
{
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = chooser.showDialog(this, "Choose Directory");
switch(result) {
case JFileChooser.APPROVE_OPTION:
listDir(chooser.getSelectedFile());
}
}
}
public void listDir(File dir)
{
File[] files = dir.listFiles();
v_titles = new Vector();
v_artist = new Vector();
v_genre = new Vector();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory())
{
listDir(files[i]);
}
else
{
if(files[i].getName().endsWith(".mp3"))
{
try
{
MP3File file = new MP3File(files[i].getAbsolutePath());
if(file.getName() != null)
m_titles.addElement(file.getName());
else
m_titles.addElement(new String(""));
if(file.getArtist() != null)
m_artist.addElement(file.getArtist());
else
m_artist.addElement(new String(""));
if(file.getGenre() != null)
m_genre.addElement(file.getGenre());
else
m_genre.addElement(new String(""));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}
}
}
public static void main(String[] args)
{
new JSplitPaneTest().setVisible(true);
}
}
weiß von euch jemand, was hier der fehler ist? :(
matti