England Forum - UK Forum
 

Go Back   England Forum - UK Forum > Computers and Technology > Developers Forum > Java Forum

 

 


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-07-2008
Peon
 
Join Date: May 2008
Posts: 34
Default Problem using GridBagLayout Java?

I have made my code shorter to try and just show the error. I am using 4 panels in a container and i have coloured each panel to show they are there. My problem is my left panel which is set to LINE_START in the container. This panel's layout is set to GridBagLayout. I am trying to create a registration type panel. I am starting off with my registration title, i have set the gridx and gridy both too 0 but my title is being put in the middle of the panel. I cant seem to get it too work from the top of the panel. Please if you could look at the code and see why this is happening. The code should compile if you like to take a look.
Thanks very much.

import java.awt.*; //the importing of required libraries
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.KeyListener;
import java.awt.event.*;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Album extends JFrame
{
private JPanel topPanel, leftPanel, centerPanel, rightPanel, bottomPanel;
private JLabel regUser, regPassword, regName, regTitle;
private JTextField regUser2, regPassword2, regName2;

private String regUser3, regPassword3, regName3;


private Container cPane;


public Album()
{
super();

createGUI();

regUser3 = "";
regPassword3 ="";
regName3 ="";

}

private void createGUI(){

cPane = getContentPane();

arrangeCompenents();

setTitle("Main");
setLocation(new Point(0, 0));
setVisible(true);
setSize(800, 608);
setDefaultCloseOperation(WindowConstants.DISPOSE_O N_CLOSE);

}


private void arrangeCompenents(){


topPanel = new JPanel();
leftPanel = new JPanel();
centerPanel = new JPanel();
rightPanel = new JPanel();
bottomPanel = new JPanel();

regUser = new JLabel("Username");
regPassword = new JLabel("Password");
regName = new JLabel("Full Name");
regTitle = new JLabel("REGISTER");

regUser2 = new JTextField(10);
regPassword2 = new JTextField(10);
regName2 = new JTextField(10);


regTitle.setFont(regTitle.getFont().deriveFont(Fon t.BOLD, 12));
regTitle.setForeground(new Color(0, 153, 254));


cPane.setLayout(new BorderLayout());
cPane.add(topPanel,BorderLayout.PAGE_START);
cPane.add(centerPanel,BorderLayout.CENTER);
cPane.add(bottomPanel, BorderLayout.PAGE_END);
cPane.add(leftPanel, BorderLayout.LINE_START);

topPanel.setBackground(Color.black);
centerPanel.setBackground(Color.green);
bottomPanel.setBackground(Color.blue);
leftPanel.setBackground(Color.white);

leftPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc01 = new GridBagConstraints();
gbc01.gridx = 0;
gbc01.gridy = 0;
gbc01.insets = new Insets(0, 0, 5, 5);
gbc01.anchor = GridBagConstraints.PAGE_END;
leftPanel.add(regTitle, gbc01);

GridBagConstraints gbc02 = new GridBagConstraints();
gbc02.gridx = 0;
gbc02.gridy = 1;
gbc02.insets = new Insets(5, 5, 5, 5);
leftPanel.add(regUser, gbc02);

GridBagConstraints gbc03 = new GridBagConstraints();
gbc03.gridx = 1;
gbc03.insets = new Insets(5, 5, 5, 5);
gbc03.gridy = 1;
gbc03.gridwidth = 2;
gbc03.fill = GridBagConstraints.BOTH;
leftPanel.add(regUser2, gbc03);

GridBagConstraints gbc04 = new GridBagConstraints();
gbc04.gridx = 0;
gbc04.gridy = 2;
gbc04.insets = new Insets(5, 5, 5, 5);
leftPanel.add(regPassword, gbc04);

GridBagConstraints gbc05 = new GridBagConstraints();
gbc05.gridx = 2;
gbc05.insets = new Insets(5, 5, 5, 5);
gbc05.gridy = 2;
gbc05.gridwidth = 2;
gbc05.fill = GridBagConstraints.BOTH;
leftPanel.add(regPassword2, gbc05);







}


public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Album();
}
});

}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links

Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:09 PM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC7
Sedo - Buy and Sell Domain Names and Websites project info: englanddebate.co.uk Statistics for project englanddebate.co.uk etracker® web controlling instead of log file analysis

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181