File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout and JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout and JScrollPane" Watch "GridBagLayout and JScrollPane" New topic

GridBagLayout and JScrollPane

Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148

I have a JPanel in a JScrollPane. I added the ScrollPane to my Frame. With a borderlayout it works fine, but I must use a GridBagLayout. If I add the ScrollPane to the Frame with a gridbaglayout and i resize the window the ScrollPane has the size of a stamp...
my panel in a ScrollPane:

in the frame:

Thanks a lot!
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
In GridBagLayout u got a lot of attributes for the gridbagconstraints class. u had to know the purpose of each of it.
just take a look at the piece of ur code which had been modified and hope it works....
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class gridbag extends JFrame
Container cont;
JPanel panel;
JScrollPane scrollpane;
GridBagLayout gridbag;
GridBagConstraints c;
cont = getContentPane();
panel = new JPanel();
scrollpane = new JScrollPane(panel);
gridbag = new GridBagLayout() ;
c = new GridBagConstraints() ;
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH ;
c.weightx = 1.0 ;
c.weighty = 1.0 ;
gridbag.setConstraints(scrollpane,c) ;
//cont.setLayout(new BorderLayout());
public static void main(String a[])
gridbag g = new gridbag();
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Thanks it works fine!
I agree. Here's the link:
subject: GridBagLayout and JScrollPane
jQuery in Action, 3rd edition