•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 397,816 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1414 | Replies: 4
![]() |
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,183
Reputation:
Rep Power: 10
Solved Threads: 265
In the JPanel I placed JTextField and JButton, as the layout I'm using GridBagLayout which is left to default align (center). However because of the size of whole JFrame I would like to get JTextField to left and JButton to right. How do I do that
private GridBagLayout gbag = new GridBagLayout();
private GridBagConstraints gbc = new GridBagConstraints();
private Border bs = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
.
.
.
.
public void setupIndexPanel()
{
panelIndex = new JPanel();
panelIndex.setBorder(new TitledBorder(bs, "Index File Path"));
panelIndex.setLayout(gbag);
tfIndex = new JTextField(20);
tfIndex.setEditable(false);
gbc.gridx = 0;
gbc.gridy = 0;
gbag.setConstraints(tfIndex, gbc);
panelIndex.add(tfIndex);
btnIndex = new JButton("Get index");
btnIndex.setPreferredSize(new Dimension(100, 30));
btnIndex.addActionListener(this);
gbc.gridx = 1;
gbc.gridy = 0;
gbag.setConstraints(btnIndex, gbc);
panelIndex.add(btnIndex);
} Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,661
Reputation:
Rep Power: 18
Solved Threads: 193
Don't try to force your design into a single layoutmanager.
Layer your layout.
You could for example place a panel in the region of the gridbag that you want those two components to appear, set that to gridlayout, and place the components in the cells of that grid.
These cells can be individually configured to have different alignment properties.
Layer your layout.
You could for example place a panel in the region of the gridbag that you want those two components to appear, set that to gridlayout, and place the components in the cells of that grid.
These cells can be individually configured to have different alignment properties.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,183
Reputation:
Rep Power: 10
Solved Threads: 265
OK, I started to break down even this two components panels, I though there is some simple/smart solution to this
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Check out the GridBagConstraints.anchor field.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,183
Reputation:
Rep Power: 10
Solved Threads: 265
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- adding scrollPane to panel with components aligned at fixed bounds (Java)
- Cant add/remove win components (Windows NT / 2000 / XP / 2003)
- Hardware - Cases - Want to separate components (Troubleshooting Dead Machines)
Other Threads in the Java Forum
- Previous Thread: Accessing frame from Action listener
- Next Thread: more syntax questions



Linear Mode