how to layout from left to right, no wrapping, no vertical scrollbar

I have a JPanel, and will drag several components to this JPanel when the program is running.

What i want is:

the JPanel has a given height (for instance 200 pixel),

the width of the JPanel will increase when I drag and drop several componens to it.

I want a special layout manager like the flowlayout: arrange all of the componentsfrom left to right, no wrapping.no verticalscrollbar, butthe horizontalscrollbar will display when needed

Idon't want to add a JScrollPane to this JPanel,just layout manager can do.

thank you for anyone who can give me some tips!

[660 byte] By [bert_suna] at [2007-10-3 3:35:51]
# 1
> I don't want to add a JScrollPane to this JPanel,You don't.You add the panel to the scroll pane. How else do you expect to get a horizontal scrollbar. It doesn't just appear magically unless you use a scroll pane.
camickra at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...
# 2
if use JScrollPane how to solve this problem,thanks
bert_suna at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...
# 3

- use a FlowLayout on your panel

- place the panel in a scroll pane with vertical and horizontal scroll bar policies of 'never' and 'as needed' respectively

- that's probably enough but you _may_ need to use a bespoke Viewport subclass to control its minimum size; suck it and see

itchyscratchya at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...
# 4

can you give me some example,

the panel i use has intialized with a special layoutmanager,

but after i change the layout manager to be flowlayout

the components in it seem to layout from left to right then go to next line, then from left to right again.

but i just want all the components always layout from left to right, no line break

thanks

bert_suna at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...
# 5
Oh, ok, FlowLayout won't work then :o)A cusom manager which does the same but doesn't wrap is pretty easy to implement.
itchyscratchya at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...
# 6
You can use a GridBagLayout. Let all the GridBagConstraints values remain at their default, exept gridx. Increment gridx each time you add a component. This should behave just like FlowLayout, except no wrapping.
BillKriegera at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...
# 7

> Oh, ok, FlowLayout won't work then :o)

No, FlowLayout will work the way the user wants. A more common complaint about the FlowLayout is that is "won't wrap" to the next line. The OP must be setting the preferred width of the container. In this case the components will wrap.

If you just create a panel, add the panel to a scrollpane and keep adding components to the panel they will go on horizontally forever.

If the OP needs further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-14 21:30:41 > top of Java-index,Desktop,Core GUI APIs...