Results 1 to 4 of 4
- 08-17-2012, 12:22 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Help me with alignment. GridBagLayout
hi. i want to align heading to the top centre and i want to align rest of my fields and labels to the left after heading. i have tried alot but cant do it.
i want to do it like this

cross-posted at: Help me in alligning . GridBagLayoutJava Code:public class Main { public static void main(String[] args) { Entry test = new Entry(); } } -------------------------- import java.awt.*; import javax.swing.*; public class Objects { JLabel top; // TextInput Fields JTextField SerialNo; JTextField RecDate; JTextField GatePassNo; JTextField BoxNo; public GridBagConstraints gbc = new GridBagConstraints(); public JPanel EntryPanel = new JPanel(new GridBagLayout()); JPanel HeadingPanel= new JPanel(); Objects() { top = new JLabel("Text1"); BoxNo = new JTextField(10); SerialNo = new JTextField(10); } } -------------------------- import java.awt.*; import javax.swing.*; public class Entry extends Objects{ public Entry() { JFrame entry= new JFrame("Text1"); entry.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); entry.setLocationRelativeTo(null); entry.setVisible(true); top.setFont(new Font("Serif",Font.BOLD,30)); entry.getContentPane().add(HeadingPanel,BorderLayout.PAGE_START); HeadingPanel.add(top); entry.getContentPane().add(EntryPanel,BorderLayout.WEST); gbc.gridx = 1; gbc.gridy=5; EntryPanel.add(BoxNo); entry.setSize(600,600); } }
-
Re: Help me with alignment. GridBagLayout
Do not use setSize(). Instead if possible let the components set their own sizes based on their need and the layout manager. You can use setPreferredSize(...) if you must set a size of a component. Always call pack() on the JFrame after adding all components which tells the layout managers to do their thing, then call setLocationXXX(...) then call setVisible(true) in that order.
- 08-17-2012, 02:17 AM #3
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Re: Help me with alignment. GridBagLayout
k thnx. but i like to make JFrame full screen. Thats why i was asking..
- 08-17-2012, 07:39 AM #4
Re: Help me with alignment. GridBagLayout
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
GridBagLayout alignment problem
By adwart in forum AWT / SwingReplies: 2Last Post: 08-15-2011, 04:58 AM -
Gridbaglayout, hint on label alignment...
By Marcoita_88 in forum AWT / SwingReplies: 1Last Post: 08-09-2011, 08:53 PM -
GUI alignment
By africanhacker in forum New To JavaReplies: 5Last Post: 03-13-2011, 09:22 PM -
pls... help.... alignment....
By eiramae in forum Java AppletsReplies: 0Last Post: 02-26-2011, 06:47 AM -
Help with alignment
By firecat318 in forum AWT / SwingReplies: 3Last Post: 05-25-2010, 03:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks