Problem with implementing an image to border layout
I've tried a few different ways of trying to solve this problem, and it seems quite easy but doesn't want to work for me.
This is my code atm that wont work:
JPanel JPanelSouth = new JPanel();
JPanelSouth.setPreferredSize(new Dimension(300, 300));
//ImageIcon.add(BorderLayout.PAGE_END);
pane.add(JPanelSouth, BorderLayout.PAGE_END);
ImageIcon timeline = new ImageIcon("timeline.gif");
JPanelSouth.add(timeline, BorderLayout.PAGE_END);
I want to add timeline to the south part of my border but can't seem to get it to work.
[582 byte] By [
RobRob47a] at [2007-11-27 0:35:13]

> I've tried a few different ways of trying to solve
> this problem, and it seems quite easy but doesn't
> want to work for me.
>
>
> This is my code atm that wont work:
>
> JPanel JPanelSouth = new JPanel();
> JPanelSouth.setPreferredSize(new Dimension(300,
> 300));
> //ImageIcon.add(BorderLayout.PAGE_END);
> pane.add(JPanelSouth, BorderLayout.PAGE_END);
> ImageIcon timeline = new
> ImageIcon("timeline.gif");
> JPanelSouth.add(timeline,
> BorderLayout.PAGE_END);
>
>
> I want to add timeline to the south part of my border
> but can't seem to get it to work.
You can resize your images first using getScaledInstance()
Define "can't seem to get it to work."
Wild guess, because I used to work on the Psychic Frendz HotLine:
JPanel JPanelSouth = new JPanel(new BorderLayout());
Did you want JPanelSouth to use a border layout as well? It's hard to guess, from your total lack of explanation.
Looks like the Op wants to place two images using BorderLayout which is not possible as the first( i am not very sure maybe even second) image would make use of the entire container to display itself for its actual resolution.
Sorry for the lack of explanation. Bassically, I want my image, timeline.gif, to be the south part of my border layout. I want nothing else to be there apart from the image.thanks so far :>
>Basically, I want my image, timeline.gif, to be the south part of my border layout. I want nothing else to be there apart from the image.
JPanel p = new JPanel(new BorderLayout());
p.add(new ImageIcon(url), BorderLayout.SOUTH);
> > JPanel p = new JPanel(new BorderLayout());
> p.add(new ImageIcon(url), BorderLayout.SOUTH);
>
I tried using this in my program but seems to give me an error with "add" and the URL I put in
Woops! Forgot put icon into a JLabel:
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class ImageInSouthExample implements Runnable {
public void run() {
URL url;
try {
url = new URL("http://www.lib.utexas.edu/maps/atlas_east_europe/albania-timeline.jpg");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
JPanel p = new JPanel(new BorderLayout());
p.add(new JLabel(new ImageIcon(url)), BorderLayout.SOUTH);
p.add(new JLabel("another component"));
JFrame f = new JFrame("ImageInSouthExample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JScrollPane(p));
f.setSize(600, 600);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new ImageInSouthExample());
}
}
Message was edited by:
DrLaszloJamf