File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes lost button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "lost button" Watch "lost button" New topic
Author

lost button

kelly bones
Greenhorn

Joined: Jan 18, 2005
Posts: 10
hello - new to this bbs - hope this is right place to post query - it is from a newby but may be swing?

a new button(4th) does not appear in my gui, yet all other buttons(3) appear - any advice on where to look for error please?

code is copied form other buttons which work and display as expected?

mystified

love

kelly
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
It could be a layout problem. Simple thing to try: resize your window. Otherwise, try posting the code. Simplify it as much as possible (i.e. divorce it from other stuff in your code).

-Jeff-


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
kelly bones
Greenhorn

Joined: Jan 18, 2005
Posts: 10
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
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Have you checked the image file names and that the images actually exist in the directory as listed? Also, I would check the case for all letters in the image name. If the directory lists image.gif, referencing the image with Image.GIF could potentially create problems. Because the blank area displays on your GUI, I'd guess you have a missing/improperly referenced image file.

Good luck!


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Welcome to the Ranch! It will probably be helpful to post your question at the GUI forum. It will be more on topic there and the experts in GUI programming are more likely to see your question.

I don't mean to discourage you asking questions. Far from it. This is just a suggestion to help you get relevant answers to your question.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
kelly bones
Greenhorn

Joined: Jan 18, 2005
Posts: 10
many thanks for your help - and a good nights sleep helped resolve it.

sorry - hate to admit it but I had a path problem with the image files

love

kelly
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lost button