Results 1 to 3 of 3
- 07-20-2010, 10:41 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Heavyweight Component resizing inside JScrollpane
Hi,
in my application i have a heavyweight component (jpanel with a few buttons, jtextfields, jtextareas, etc) that i put in a scrollpane.
the scrollpane is supposed to only scroll vertically - in the horizontal direction, i want to resize the components in the scrollpane to the appropriate size depending on the main frame of the application.
when the application starts, everything is fine and the components take up the available size.
when i increase the application window size hotizonally, the components (mainly the jTF and jTA) increase in size, as it is's supposed to be.
But once i decrease the horizontal size again, the jTF and jTA stay the size they were before and do not shrink as i want them to.
If i just add the jpanel without putting it inside a jscrollpane, the resizing works perfect. i need a vertical scroller though, so this is not an option.
here is a picture that shows the resizing behaviour:

inside the JPanel that is inside the scrollpane i use a grouplayout.
here is a portion of my code that shows how one of the components inside the panel is layed out.
If other code portions are needed, please tell me.Java Code:// component layout for the LINKS panel // horizontal groups SequentialGroup hGroup = layout.createSequentialGroup(); ParallelGroup h2 = layout.createParallelGroup(); ParallelGroup h3 = layout.createParallelGroup(); ParallelGroup h4 = layout.createParallelGroup(); h2.addComponent(linkListScrollPane, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE); h3.addComponent(bAddLink); h4.addComponent(bRemoveLink); hGroup.addGroup(h2); hGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED); hGroup.addGroup(h3); hGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED); hGroup.addGroup(h4); layout.setHorizontalGroup(hGroup); // vertical groups SequentialGroup vGroup = layout.createSequentialGroup(); ParallelGroup v1 = layout.createParallelGroup(); v1.addComponent(linkListScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); v1.addComponent(bAddLink); v1.addComponent(bRemoveLink); vGroup.addGroup(v1); layout.setVerticalGroup(vGroup);
I hope someone can help me with this one :)
- 07-20-2010, 01:11 PM #2
Hi,
1)JScrollPane supports lightWeight component only.
2)JPanel, JTextField etc r lightWright.
&
3)I don't use JScrollPane, but still check this out.
-regardsJava Code:JScrollPane jsp = new JScrollPane(); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
- 07-20-2010, 01:58 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 11
- Rep Power
- 0
Hi,
thanks for you answer Prajin. Unfortunately it wont solve the problem since the components still remain too large.
I've found a solution that works though.
You need to set the preferredSize of the JPanel inside the JScrollPane.
This way, the components inside the JPanel try to shrink according to the preferredSize.
How it looks now:
Java Code:// code part building the gui // scrollpane JScrollPane frameEditorScroller = new JScrollPane(new FrameEditor()); frameEditorScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); frameEditorScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // panel class that resides in the jscrollpane public class FrameEditor extends JPanel { public FrameEditor() this.setPreferredSize(new Dimension(500, 400); // + other stuff below } }Last edited by random7; 07-20-2010 at 02:12 PM.
Similar Threads
-
Transarent background over heavyweight components
By cartoon_20 in forum AWT / SwingReplies: 3Last Post: 05-31-2010, 09:14 PM -
using awt inside an swt component
By Jyo in forum AWT / SwingReplies: 0Last Post: 05-26-2010, 07:06 PM -
panel resizing
By simo_mon in forum AWT / SwingReplies: 1Last Post: 08-15-2009, 02:09 PM -
JFrame resizing
By carderne in forum New To JavaReplies: 3Last Post: 07-22-2009, 07:42 PM -
how to draw an image inside of jscrollpane
By paty in forum Java AppletsReplies: 1Last Post: 07-24-2007, 12:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks