Make the component stretch in both directions : GridBagLayout « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Swing JFC » GridBagLayoutScreenshots 
Make the component stretch in both directions
 

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] argvthrows Exception {
    JFrame frame = new JFrame();
    GridBagLayout gbl = new GridBagLayout();

    frame.setLayout(gbl);
    JButton component = new JButton("1");
    frame.add(component);
    frame.add(new JButton("2"));

    gbl.layoutContainer(frame);

    GridBagConstraints gbc = new GridBagConstraints();

    gbc.fill = GridBagConstraints.BOTH;

    gbl.setConstraints(component, gbc);
    frame.add(component);

    frame.pack();
    frame.setVisible(true);
  }
}

   
  
Related examples in the same category
1. GridBagLayout with weightx and weighty constraintsGridBagLayout with weightx and weighty constraints
2. GridBagLayout with constraintsGridBagLayout with constraints
3. Simplest gridbag layoutSimplest gridbag layout
4. GridBagLayout with weight constraintGridBagLayout with weight constraint
5. GridBagLayout with anchor constraintsGridBagLayout with anchor constraints
6. GridBagLayout with gridwidth and gridheight constraintsGridBagLayout with gridwidth and gridheight constraints
7. GridBagLayout PaneGridBagLayout Pane
8. Work with GridBagConstraints 1
9. Work GridBagConstraints 3
10. Work with GridBagConstraints 2
11. GridBagConstraints.BOTH
12. Create and set a gridbag layout and how to set gridbag constraints
13. Associate the gridbag constraints with the component
14. Place a component at cell location (1,1)
15. Setting the Location of a Component in a GridBagLayout
16. Making a GridBagLayout Fill the Container
17. Getting the Number of Rows and Columns of Cells in a GridBagLayout
18. Setting the Stretchyness of Rows and Columns in a GridBagLayout Using Layout Weights
19. Place a component at (0,1) with a column weight 1 and a row weight of 2
20. Setting Stretchyness of a GridBagLayout Using Fill
21. Make the component only stretch horizontally
22. Make the component only stretch vertically
23. Make the component on stretchable
24. Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets
25. A GridBagLayout Example: weightx, weighty
26. Positioning a component in the center of other component using GridbagLayout
27. Work with GridBagConstraints 5
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.