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 / General / August 2006

Tip: Looking for answers? Try searching our database.

Swing, beginner question

Thread view: 
Jelena Marin - 14 Aug 2006 15:45 GMT
Have put in a lot of hours trying to get this work including a lot of
searching for the solution on the Internet but have been unable to find a
solution.  

I have a Java program that generates graphics on a JPanel.  The graphics
are not fully displayed because they overlay each other with this BoxLayout
that I am using.  The window layout should look like this:
http://img146.imageshack.us/my.php?image=windowxl0.jpg.  

Idea is to put every single graphics on separate panel; panel 2 and 3 must
be always visible when scrolling, so when I scroll to the right only panels
'1' and '3' are moving, and when scrolling down, only the '1' and '2' are
moving.  How can I achieve that?  Which layout?

This is the part of the code (third panel is not yet included) which is not
workig properly: only the 1/5 of the panel 2 is visible.  When I put
everything in JScrollPane I get blank window...

public class Applet extends JApplet
{
 public void init ()
 {   
    JPanel graphics1 = new JPanel();
    JPanel graphics2 = new JPanel();
    graphics1.setLayout (new BoxLayout (graphics1, BoxLayout.LINE_AXIS));
       graphics2.setLayout (new BoxLayout (graphics2, BoxLayout.LINE_AXIS));

    graphics1.add (new drawGraphics1()); //
    graphics2.add (new drawGraphics2()); // drawing only lines with
paintComponent
   
    JPanel panel = new JPanel();
       panel.setLayout (new BoxLayout (panel, BoxLayout.LINE_AXIS));
       panel.add (graphics1);
       panel.add (graphics2);
       JScrollPane scroller = new JScrollPane (panel);
      
       Container cp = getContentPane();
       cp.add (panel);  // panel 2 is shrinked
       //cp.add (scroller);  //blank window
      
       public void init ()
       {
           ...
       }
 }
 
 public static void main (String[] args)
 {
     ...
 }
Thomas Weidenfeller - 14 Aug 2006 16:12 GMT
> http://img146.imageshack.us/my.php?image=windowxl0.jpg.  

For me that URL comes up with an add for a software called
"drivecleaner". That add uses some primitive scare tactics "you have
been scanned", "you use ...", "you live in ..." to convince me to buy
the software. It further claims to run a "scan" on my workstation (ha,
ha, ha).

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Jelena Marin - 14 Aug 2006 17:14 GMT
>> http://img146.imageshack.us/my.php?image=windowxl0.jpg.  
>
[quoted text clipped - 3 lines]
> the software. It further claims to run a "scan" on my workstation (ha,
> ha, ha).

http://aycu31.webshots.com/image/1590/2002538770839726749_rs.jpg
cp - 14 Aug 2006 16:58 GMT
For the JScrollPane you need to set the preferred size e.g.
scroller.setPreferredSize(size x, size y);
Jelena Marin - 14 Aug 2006 17:20 GMT
> For the JScrollPane you need to set the preferred size e.g.
> scroller.setPreferredSize(size x, size y);

scroller.setPreferredSize(new Dimension (400, 400));

Nope, that doesn't help, still have blank window.  :(
shiv_koirala@yahoo.com - 14 Aug 2006 17:10 GMT
Guessing...Set your preferred size....

Regards
Shiv
Free 1000 Java Interview questions with answers
http://www.questpond.com
danharrisandrews@gmail.com - 14 Aug 2006 17:12 GMT
Hi Jelena,

My guess is that your Component objects "drawGraphics1" and
"drawGraphics2" should be setting their preferred size (e.g.
setPreferredSize(new Dimension(100, 400);). Please note that not all
layout managers treat minimum, maximum, and preferred size the same
way. Have a look here for more information on layout managers
(http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html).

Cheers,

Dan Andrews

- - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - -

> Have put in a lot of hours trying to get this work including a lot of
> searching for the solution on the Internet but have been unable to find a
> solution.
Jelena Marin - 14 Aug 2006 18:19 GMT
> Hi Jelena,
>
> My guess is that your Component objects "drawGraphics1" and
> "drawGraphics2" should be setting their preferred size (e.g.

But when I define new JFrame, and then put everything in frame, and after
that I put that frame in applet container, everything works perfectly?!  I
don't understand this at all.  :(
Knute Johnson - 16 Aug 2006 04:32 GMT
>> Hi Jelena,
>>
[quoted text clipped - 4 lines]
> that I put that frame in applet container, everything works perfectly?!  I
> don't understand this at all.  :(

Are you using setSize() on the JFrame?  It's all tied up in the layout
manager and the sizing, some of which is automatic and some isn't.  Try
putting it all in another JPanel that has BorderLayout and that has a
set size.


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



©2009 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.