aspose file tools*
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
Author

GridBagLayout and JScrollPane

Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Hi,

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
Hi,
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;
gridbag()
{
cont = getContentPane();
panel = new JPanel();
scrollpane = new JScrollPane(panel);
gridbag = new GridBagLayout() ;
c = new GridBagConstraints() ;
cont.setLayout(gridbag);
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());
cont.add(scrollpane);
}
public static void main(String a[])
{
gridbag g = new gridbag();
g.setSize(300,300);
g.setVisible(true);
}
}
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Thanks it works fine!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout and JScrollPane