hi Jeff
have tried all sorts of re-size and re-organising layout
code snippet:
private void initGui()
{
Container theContainer = getContentPane(); // add swing components here
mainPanel = new JPanel()
{ImageIcon image = new ImageIcon("Images\\Clifton_Bridge.jpg");
{setOpaque(false);} public void paintComponent (Graphics g)
{ g.drawImage(image.getImage(), 0, 0, this); super.paintComponent(g);}
};
mainPanel.setLayout(new BorderLayout());
listModel = new DefaultListModel();
list = new JList(listModel);
list.setOpaque(false);
listModel.addElement("<<your playlist files>>");
JScrollPane scrollPane = new JScrollPane(list);
list.setCellRenderer(new MyCellRenderer());
scrollPane.setOpaque(false);
scrollPane.setBorder(null);
scrollPane.getViewport().setOpaque(false);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new ListSelectionListener()
{ public void valueChanged(ListSelectionEvent e)
{if (e.getValueIsAdjusting()) return;
System.out.println(list.getSelectedValue());
if (list.getSelectedIndex() > 0)
player.start(list.getSelectedValue().toString());
}
});
listPanel = new JPanel();//holds playlist
listPanel.setLayout(new BorderLayout());
listPanel.setPreferredSize(new Dimension(50,50));
listPanel.setOpaque(false);
listPanel.add(scrollPane, BorderLayout.CENTER);
controlPanel = new JPanel();//holds icon panel [control buttons]
controlPanel.setLayout(new BorderLayout());
controlPanel.setOpaque(false);
controlPanel.setPreferredSize(new Dimension(500,100));
iconPanel = new JPanel();//holds control buttons
iconPanel.setPreferredSize(new Dimension(500,80));
iconPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
iconPanel.setOpaque(false);
gridPanel = new JPanel();// sets output text
gridPanel.setLayout(new GridLayout(4,2));
gridPanel.setPreferredSize(new Dimension(580, 120));
gridPanel.setOpaque(false);
stopButton = createBaseButton("Stop", 20, 20); // stopButton
stopButton.setIcon(new ImageIcon("Images\\Stop_B&W.GIF"));
stopButton.setRolloverIcon(new ImageIcon("Images\\Stop_Green.GIF"));
stopButton.setPressedIcon(new ImageIcon("Images\\Stop_Red.GIF"));
iconPanel.add(stopButton);
stopButton.addActionListener(this);
prevButton = createBaseButton("Prev", 20, 20); // prevButton
prevButton.setIcon(new ImageIcon("Images\\Prev_B&W.GIF"));
prevButton.setRolloverIcon(new ImageIcon("Images\\Prev_Green.GIF"));
prevButton.setPressedIcon(new ImageIcon("Images\\Prev_Red.GIF"));
iconPanel.add(prevButton);
prevButton.addActionListener(this);
pauseButton = createBaseButton("Pause", 20, 20); // pauseButton
pauseButton.setIcon(new ImageIcon("Images\\Pause_B&W.GIF"));
pauseButton.setRolloverIcon(new ImageIcon("Images\\Pause_Green.GIF"));
pauseButton.setPressedIcon(new ImageIcon("Images\\Pause_Red.GIF"));
iconPanel.add(pauseButton);
pauseButton.addActionListener(this);
playButton = createBaseButton("Play", 20, 20);// playButton
playButton.setIcon(new ImageIcon("Images\\Play_B&W.GIF"));
playButton.setRolloverIcon(new ImageIcon("Images\\Play_Green.GIF"));
playButton.setPressedIcon(new ImageIcon("Images\\Play_Red.GIF"));
iconPanel.add(playButton);
playButton.addActionListener(this);
controlPanel.add(iconPanel, BorderLayout.SOUTH);
artist = new JLabel("Artist");
album = new JLabel("Album");
title = new JLabel("Track");
time = new JLabel("Time");
top = new JPanel();//holds title right justified
top.setOpaque(false);
top.setLayout(new FlowLayout(FlowLayout.TRAILING));
top.setPreferredSize(new Dimension(500,110));
JLabel name = new JLabel("Java MP3 Player");
top.add(name);
gridPanel.add(artist);
gridPanel.add(album);
gridPanel.add(title);
gridPanel.add(time);
lpan = new JPanel();//padding to left side of GUI
lpan.setOpaque(false);
lpan.setPreferredSize(new Dimension(50,200));
rpan = new JPanel();//padding to right side of GUI
rpan.setOpaque(false);
rpan.setPreferredSize(new Dimension(50,200));
textPanel = new JPanel();// holds list and labels output
textPanel.setPreferredSize(new Dimension(480, 200));
textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
textPanel.setOpaque(false);
textPanel.add(gridPanel);
textPanel.add(listPanel);
mainPanel.setPreferredSize(new Dimension(580, 466));
mainPanel.add(controlPanel, BorderLayout.SOUTH);
// mainPanel.add(iconPanel, BorderLayout.SOUTH);
mainPanel.add(top, BorderLayout.NORTH);
mainPanel.add(lpan, BorderLayout.WEST);
mainPanel.add(rpan, BorderLayout.EAST);
mainPanel.add(textPanel, BorderLayout.CENTER);
theContainer.add(mainPanel);
setLocation(50,100);
}// end of initGUI()
the new button added is prevButton which follows all other JButton styles with roll over images etc. When I look closely at the running code there is a blank 'grey' 20 x 20 pixel square between the stop and pause JHButtons which is the place I expected to find prevButton. I tried it here after it failed to appear to the left of stopButton?
still mystified?
it is clearly my college assignment. I'm reasonably happy with my code so far but this is really stumping me? any ideas for solving would be very much appreciated - love
Kelly