• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GridBagLayout and JScrollPane

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks it works fine!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic