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 / March 2005

Tip: Looking for answers? Try searching our database.

Border layout and Jlist

Thread view: 
Daniel Santos - 23 Mar 2005 23:53 GMT
Hello,

I have the following structure of components in a internal frame:

JInternalFrame (BorderLayout)
    - JPanel (BorderLayout) (BorderLayout.WEST)
        - JScrollPane (BorderLayout.CENTER)
            - JList
    - JPanel (BorderLayout) (BorderLayout.CENTER)
        - JButton (BorderLayout.CENTER)

What I want to do with this is to have the first JPanel with a fixed
width and resizable height and the second JPanel resizable in both
dimensions.

I set a preferred size on the JPanel containing the scroll pane and that
  works.
My problem is that the JList appears with zero dimension. I just want
the list to stretch to the borders of the containing JPanel.

Anyone can help?
Many thanks
Daniel Santos
Hiroshi Iwatani - 24 Mar 2005 10:56 GMT
> Hello,
>
[quoted text clipped - 19 lines]
> Many thanks
> Daniel Santos

I like to see a small test program code that can reproduce your problem.
Daniel Santos - 24 Mar 2005 18:50 GMT
>> Hello,
>>
[quoted text clipped - 21 lines]
>
> I like to see a small test program code that can reproduce your problem.

Hello,

Here goes the main method of a test class. I am actually trying to do it
with SwiXML.

    public static void main(String[] args) {
       
        JFrame frame = new JFrame();
        frame.setSize(new Dimension(800, 600));
        frame.setLayout(null);
        JDesktopPane desktop = new JDesktopPane();
        frame.setContentPane(desktop);
       
        JInternalFrame internalFrame = new JInternalFrame();
        internalFrame.setSize(new Dimension(600,200));
        internalFrame.setLayout(new BorderLayout());
        internalFrame.setLocation(new Point(10,10));
        internalFrame.setResizable(true);
       
        JScrollPane scrollpane = new JScrollPane();
        JList list = new JList();
        scrollpane.add(list);
        DefaultListModel model = new DefaultListModel();
        list.setModel(model);
        list.setVisibleRowCount(5);
        model.addElement("bla");
       
        JButton button = new JButton("Button");
       
        JPanel listPanel = new JPanel();
        listPanel.setLayout(new BorderLayout());
        listPanel.add(scrollpane, BorderLayout.CENTER);
        listPanel.setPreferredSize(new Dimension(100,200));
        internalFrame.getContentPane().add(listPanel, BorderLayout.WEST);
       
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new BorderLayout());
        buttonPanel.add(button);
        internalFrame.getContentPane().add(buttonPanel, BorderLayout.CENTER);
        internalFrame.setVisible(true);
       
        frame.getContentPane().add(internalFrame);
        frame.setVisible(true);
    }

Regards,
Daniel Santos
hiwa - 25 Mar 2005 03:12 GMT
> scrollpane.add(list);
This line is wrong.
should be:
scrollpane.getViewport().add(list);

Besides, in a real-world professional developement, never set container
layout null.
See FAQ of the comp.lang.java.gui.
Daniel Santos - 25 Mar 2005 10:33 GMT
>  > scrollpane.add(list);
> This line is wrong.
[quoted text clipped - 4 lines]
> layout null.
> See FAQ of the comp.lang.java.gui.

Well..., thankyou for your "professional" answer.
If I don't want a layout what do you "professionaly" advise me to do?
hiwa - 26 Mar 2005 00:56 GMT
> I don't want a layout

You want.
Daniel Santos - 29 Mar 2005 11:41 GMT
>> I don't want a layout
>
> You want.

Allow me to explain myself better. I want a null layout, so I can set
the positions of components with absolute coordinates. That's why I am
setting it to null.

Regards,
Daniel Santos
Thomas Weidenfeller - 30 Mar 2005 08:13 GMT
> Allow me to explain myself better. I want a null layout,

You don't. You just want to dodge learning layout managers.

> so I can set
> the positions of components with absolute coordinates. That's why I am
> setting it to null.

You said you want to have resizable components (Message-ID:
<4241f536$0$24083$a729d347@news.telepac.pt>).

Conclusion: You need layout managers. Insisting on not using one
therefore doesn't make much sense.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

Aki \ - 30 Mar 2005 08:22 GMT
>> Allow me to explain myself better. I want a null layout,
>
> You don't. You just want to dodge learning layout managers.

Which, I can tell from experience, is a Bad Idea with capital letters.
I started a programming project without knowing anything about layout
managers and ended up in a world of trouble.

>> so I can set the positions of components with absolute coordinates.
>> That's why I am setting it to null.
[quoted text clipped - 4 lines]
> Conclusion: You need layout managers. Insisting on not using one
> therefore doesn't make much sense.

Indeed. And even withou the need for resizeable components, it's rather
sloppy not to define any layout managers. I, too, suggest you learn
about different layout managers, experiment with different layouts and
then decide which layout managers to use where. Components' minimum,
preferred and maximum sizes are also important when defining layouts.

Signature

-Aki "Sus" Laukkanen
"Älä multa kysy tai mä vastaan!"
"Don't ask me or I'll answer!"

Daniel Santos - 30 Mar 2005 17:41 GMT
Aki "Sus" Laukkanen wrote:

>>> Allow me to explain myself better. I want a null layout,
>>
[quoted text clipped - 18 lines]
> then decide which layout managers to use where. Components' minimum,
> preferred and maximum sizes are also important when defining layouts.

Hello,

Thanks for your answers, I agree completely with having to learn layouts.

The container where I was setting the layout to null is a JFrame.What I
have is some internal frames inside the desktop pane. Internal frames
always have to be sized and positioned using API calls.
Does it matter in that case ?

Regards,
Daniel Santos


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.