Im designing a GUI for my java and what I have done is added the buttons to the EAST side and a pic to the Centre. I like a border to split the button. Something in between to splits them apart so it looks much nicer. Can anyone suggest something to me and give me a example coding of how it shud be done.
Thanx
:rolleyes:
02-20-2005, 07:33 PM
sjalle
This is one way. The mainPanel can be substistuted
w. a JFrame (just remember to use the
getContentPane().add() instead of add()): The gridlayout
in the eastPanel is set up w. 0 rows and 1 column, this
makes the components line up in a column like big fat buttons.
Code:
// declare components
JPanel mainPanel = new JPanel();
JPanel eastPanel = new JPanel();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
GridLayout gridLayout2 = new GridLayout();
GridLayout gridLayout3 = new GridLayout();
GridLayout gridLayout4 = new GridLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
I have added the buttons to the west putting the labels inbetween the buttons to give them space in the centre I have added a picture in the centre ..Now thought about button b being used for the border between the buttons and the pic but I tried and I cant do it..I left you my code at the moment which u can mess around with to produce what I what…..
Thank you a lot
:confused:
public SalesControlFrame() {
setLayout(new BorderLayout());
setBackground(Color.blue);
setTitle("Sales Control & Stock");
setSize(new Dimension(600, 500));
leftPanel = new Panel(new GridLayout(9,2 ));
add(leftPanel, BorderLayout.WEST);
topPanel = new Panel(new GridLayout(2,1 ));
add(topPanel, BorderLayout.NORTH);
//Image Setting
pic = new ImageIcon("G:/img/vz.jpg");
picture1 = new JLabel(pic);
rightPanel = new Panel();
//Setting the image on the right
rightPanel = new Panel(new GridLayout(1,1));
add(rightPanel, BorderLayout.CENTER);
centerPanel = new Panel(new GridLayout(1,1));
add(centerPanel, BorderLayout.EAST);
//Adding New Buttons
viewButton= new Button("Moniter Material");
cuButton= new Button("Customer Order");
spButton = new Button("Reorder From Suppliers");
Exit = new Button("Exit");
b = new Button("");
//Adding labels for space on the buttons
JLabel A = new JLabel("");
JLabel B = new JLabel("");
JLabel C = new JLabel("");
JLabel D = new JLabel("");
JLabel cpLabel = new JLabel("Company Address");
JLabel uslabel = new JLabel( "User Details");
Too complicated, hmm ?
You are using labels as 'bricks' , also you are using a mixture of swing and awt components (JLabel, Panel) ??
Your solution ends up w. buttons that resize as you
resize the frame (and so does my last solution :rolleyes: )
and that's not entirely kosher, in fact its a nono in gui
construction.
Try this;
Set the preferred size of the buttonspanel to say 120,10 (the height has no effect as it is stretched by
the borderlayout). Set the buttonspanel layout to:
FlowLayout(FlowLayout.LEFT). Set a fixed width for your
buttons so only one fits on each row. This will make the
buttons align left, stacked above each other and give
some right-space between the buttons and the picture.
And dont use labels for spacing here, use this: