Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2005

Tip: Looking for answers? Try searching our database.

adding pictures to a JPanel

Thread view: 
pete - 24 Jul 2005 18:57 GMT
Hi!

I have two problems with adding pictures to a JPanel.

Unfortunately if the amount of pictures I want to add is too high, it takes
a long time until my application goes on.
It waits until all pictures are loaded with a complete grey screen instead
of showing its normal behaviour.
How can I solve this problem? The answer to FAQ Q3.1 says something about
threads. Is there an other solution?

And the other problem: all pictures are added in one line. I would like to
have a newline after each 5 pictures.
I tried FlowLayout and GridLayout in combination with "SwingConstants.LEFT"
or ...RIGHT...
Is there a SwingConstant NewLineAfter or something like that?
I think GridLayout is best suitable layout for that kind of positioning the
pictures, but I don´t know how to do...

This is how I tried:

[code]
public void createContentPanel(Vector media){
...
while(i < media.size()){
  String temp = (String)media.get(i);
  try{
       temp_url = new URL(temp);
  }catch(Exception e){temp_url = null;System.out.print(false);}

   if(temp_url !=null){
      img = getToolkit().createImage(temp_url);

      ImageIcon icon = new ImageIcon(img);
      if(i%5==0)
           label = new JLabel("",icon,SwingConstants.LEFT);
      else
           label = new JLabel("",icon,SwingConstants.CENTER);

      contentPanel.add(la);
      i++;
 }
 repaint();
 setVisible(true);

[/code]

Thanks for any help!
pete
Andrew Thompson - 24 Jul 2005 20:02 GMT
> I have two problems with adding pictures to a JPanel.
>
[quoted text clipped - 4 lines]
> How can I solve this problem? The answer to FAQ Q3.1 says something about
> threads.

More specifically, it warns against "..blocking the
event dispatching thread (EDT)."

>..Is there an other solution?

While still blocking the EDT?  No.  

See 3.2.  It is not that difficult, once you get used to it.

> And the other problem: all pictures are added in one line. I would like to
> have a newline after each 5 pictures.
> I tried FlowLayout and GridLayout in combination with "SwingConstants.LEFT"
> or ...RIGHT...

Have you tried reading the JavaDocs? *

> Is there a SwingConstant NewLineAfter or something like that?
> I think GridLayout is best suitable layout for that kind of positioning the
> pictures, but I don´t know how to do...

<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/GridLayout.html#GridLayout(int,
%20int
)>
 setLayout( new GridLayout(0,4) );

* Good entry point to the on-line JavaDocs..
<http://java.sun.com/j2se/1.5.0/docs/api/overview-summary.html>

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
A By-Product Of The TV Industry



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.