• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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!
 
Have you no shame? Have you no decency? Have you no tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic