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]
# 1

> 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()

qUesT_foR_knOwLeDgea at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...
# 2

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.

DrLaszloJamfa at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...
# 3
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.
qUesT_foR_knOwLeDgea at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...
# 4
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 :>
RobRob47a at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...
# 5

>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);

DrLaszloJamfa at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...
# 6

> > 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

RobRob47a at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...
# 7

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

DrLaszloJamfa at 2007-7-11 22:43:27 > top of Java-index,Java Essentials,New To Java...