borderlayout problem

hey i am using a JFrame that has a borderlayout ,

in the center i have a panel that have in it 11 buttons,

on the left i have a panel that have in it a jspinner that a a titeled border,

the problem is that this spinner doesnt show properly, half of it is shown and the tilte for the border cant be seen,

i have tried to use setPreferredsize for the panel and for the spinner but i havent got any result...

please help me

thanks in advance

[485 byte] By [fouadka] at [2007-10-3 9:47:57]
# 1
Post a Short,Self Contained, Compilable and Executable, Example Program.And use code tags.
zadoka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 2

thanks for your reply and sorry for the delay

thats my source code, please help me

import javax.swing.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.*;

public class Test extends JFrame implements ActionListener{

JPanel upanel,lpanel,cpanel,spanel;

JTextField namefield,lastnamefield,phonefield,total;

JSpinner sp;

JButton pants,chemise,mansuit,womansuit,dress,skirt,coat,blanket,lhaf,curtains,weddingdress,ok,cancel;

Font f= new Font("Times New Roman",Font.BOLD,24);

public Test(){

Creategui();

}

public void Creategui (){

setDefaultCloseOperation(EXIT_ON_CLOSE);

setLayout(new BorderLayout());

setSize(800,600);

upanel =new JPanel();

upanel.setBackground(Color.white);

add(upanel,BorderLayout.NORTH);

lpanel=new JPanel();

lpanel.setBackground(Color.white);

add(lpanel,BorderLayout.WEST);

cpanel=new JPanel();

cpanel.setBackground(Color.white);

cpanel.setLayout(new GridLayout(3,4,5,5));

add(cpanel,BorderLayout.CENTER);

spanel=new JPanel();

spanel.setBackground(Color.white);

add(spanel,BorderLayout.SOUTH);

namefield=new JTextField(10);

namefield.setBackground(Color.white);

namefield.setEditable(false);

namefield.setBorder(BorderFactory.createTitledBorder("Name"));

upanel.add(namefield);

lastnamefield=new JTextField(10);

lastnamefield.setBackground(Color.white);

lastnamefield.setEditable(false);

lastnamefield.setBorder(BorderFactory.createTitledBorder("Last Name"));

upanel.add(lastnamefield);

phonefield=new JTextField(10);

phonefield.setBackground(Color.white);

phonefield.setEditable(false);

phonefield.setBorder(BorderFactory.createTitledBorder("Phone"));

upanel.add(phonefield);

total= new JTextField(10);

total.setEditable(true);

total.setBorder(BorderFactory.createTitledBorder("Total"));

spanel.add(total);

sp=new JSpinner();

sp.setBackground(Color.white);

sp.setBorder(BorderFactory.createTitledBorder("Quantity"));

sp.setAlignmentX(JPanel.CENTER_ALIGNMENT);

lpanel.add(sp);

ok=new JButton("OK");

ok.setFont(new Font("Times New Roman",Font.BOLD,14));

spanel.add(ok);

cancel=new JButton("Cancel");

cancel.setFont(new Font("Times New Roman",Font.BOLD,14));

spanel.add(cancel);

pants=new JButton("Pantalon");

pants.setFont(f);

cpanel.add(pants);

chemise=new JButton("Chemise");

chemise.setFont(f);

cpanel.add(chemise);

mansuit= new JButton("badle");

mansuit.setFont(f);

cpanel.add(mansuit);

womansuit= new JButton("ta2m");

womansuit.setFont(f);

cpanel.add(womansuit);

dress= new JButton("dress");

dress.setFont(f);

cpanel.add(dress);

skirt=new JButton("skirt");

skirt.setFont(f);

cpanel.add(skirt);

coat=new JButton("coat");

coat.setFont(f);

cpanel.add(coat);

blanket=new JButton("hram");

blanket.setFont(f);

cpanel.add(blanket);

lhaf=new JButton("lahf");

lhaf.setFont(f);

cpanel.add(lhaf);

curtains=new JButton("curtains");

curtains.setFont(f);

cpanel.add(curtains);

weddingdress=new JButton("weddingdress");

weddingdress.setFont(f);

cpanel.add(weddingdress);

}

/**

* Invoked when an action occurs.

*/

public void actionPerformed(ActionEvent e) {

//To change body of implemented methods use File | Settings | File Templates.

}

public static void main(String[] args){

Test t = new Test();

t.setVisible(true);

}

}

fouadka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 3
When you create your lPanel give it a layout:lpanel=new JPanel(new FlowLayout());Then set the preferred size of the spinner:sp.setPreferredSize(new Dimension(100,100));
zadoka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 4
thanks for your help, i did try this before but i tried it with a 10 dimension, i dunno why i havent chose much bigger values...thanks for your help, ill try it with 100 and ask you again if i get in trouble...thanks again
fouadka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 5

thanks for the help,

i did apply a layout and used the setprefferedsize method, it didnt work as excpected, now it shows fully in width but it also take the full height

import javax.swing.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.*;

public class Test extends JFrame implements ActionListener{

JPanel upanel,lpanel,cpanel,spanel;

JTextField namefield,lastnamefield,phonefield,total;

JSpinner sp;

JButton pants,chemise,mansuit,womansuit,dress,skirt,coat,blanket,lhaf,curtains,weddingdress,ok,cancel;

Font f= new Font("Times New Roman",Font.BOLD,24);

public Test(){

Creategui();

}

public void Creategui (){

setDefaultCloseOperation(EXIT_ON_CLOSE);

setLayout(new BorderLayout());

setSize(800,600);

upanel =new JPanel();

upanel.setBackground(Color.white);

add(upanel,BorderLayout.NORTH);

lpanel=new JPanel();

lpanel.setLayout(new GridLayout(1,1));

lpanel.setPreferredSize(new Dimension(100,50));

lpanel.setBackground(Color.white);

add(lpanel,BorderLayout.WEST);

cpanel=new JPanel();

cpanel.setBackground(Color.white);

cpanel.setLayout(new GridLayout(3,4,5,5));

add(cpanel,BorderLayout.CENTER);

spanel=new JPanel();

spanel.setBackground(Color.white);

add(spanel,BorderLayout.SOUTH);

namefield=new JTextField(10);

namefield.setBackground(Color.white);

namefield.setEditable(false);

namefield.setBorder(BorderFactory.createTitledBorder("Name"));

upanel.add(namefield);

lastnamefield=new JTextField(10);

lastnamefield.setBackground(Color.white);

lastnamefield.setEditable(false);

lastnamefield.setBorder(BorderFactory.createTitledBorder("Last Name"));

upanel.add(lastnamefield);

phonefield=new JTextField(10);

phonefield.setBackground(Color.white);

phonefield.setEditable(false);

phonefield.setBorder(BorderFactory.createTitledBorder("Phone"));

upanel.add(phonefield);

total= new JTextField(10);

total.setEditable(true);

total.setBorder(BorderFactory.createTitledBorder("Total"));

spanel.add(total);

sp=new JSpinner();

sp.setBackground(Color.white);

sp.setBorder(BorderFactory.createTitledBorder("Quantity"));

lpanel.add(sp);

ok=new JButton("OK");

ok.setFont(new Font("Times New Roman",Font.BOLD,14));

spanel.add(ok);

cancel=new JButton("Cancel");

cancel.setFont(new Font("Times New Roman",Font.BOLD,14));

spanel.add(cancel);

pants=new JButton("Pantalon");

pants.setFont(f);

cpanel.add(pants);

chemise=new JButton("Chemise");

chemise.setFont(f);

cpanel.add(chemise);

mansuit= new JButton("badle");

mansuit.setFont(f);

cpanel.add(mansuit);

womansuit= new JButton("ta2m");

womansuit.setFont(f);

cpanel.add(womansuit);

dress= new JButton("dress");

dress.setFont(f);

cpanel.add(dress);

skirt=new JButton("skirt");

skirt.setFont(f);

cpanel.add(skirt);

coat=new JButton("coat");

coat.setFont(f);

cpanel.add(coat);

blanket=new JButton("hram");

blanket.setFont(f);

cpanel.add(blanket);

lhaf=new JButton("lahf");

lhaf.setFont(f);

cpanel.add(lhaf);

curtains=new JButton("curtains");

curtains.setFont(f);

cpanel.add(curtains);

weddingdress=new JButton("weddingdress");

weddingdress.setFont(f);

cpanel.add(weddingdress);

}

/**

* Invoked when an action occurs.

*/

public void actionPerformed(ActionEvent e) {

//To change body of implemented methods use File | Settings | File Templates.

}

public static void main(String[] args){

Test t = new Test();

t.setVisible(true);

}

}

please help...

thanks in advance

fouadka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 6
Use a flow layout instead of a grid layout. A grid layout will expand. See my previous reply for an example.
zadoka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 7

i think a flowlayout would get the OP back to the scrunched-up spinner

try these changes

//lpanel.setLayout(new GridLayout(1,1));

lpanel.setLayout(new BorderLayout());

and

//lpanel.add(sp);

lpanel.add(sp,BorderLayout.NORTH);

will put the spinner at the top of the panel, and the width of the panel

if you want it in the middle use a GridBagLayout

Michael_Dunna at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 8

[nobr]hi!

i hope this code can meet up with your requirement

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JSpinner;

import javax.swing.JTextField;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

/**

* @author: aniruddha<br>

* @date: Nov 15, 2006, 10:08:38 AM<br>

* @source: SpinnerProblem.java<br>

* @project: HelpForum<br>

*/

/**

* @author aniruddha

*

*/

public class SpinnerProblem extends JFrame implements ActionListener{

JPanel upanel,lpanel,cpanel,spanel;

JTextField namefield,lastnamefield,phonefield,total;

JSpinner sp;

JButton pants,chemise,mansuit,womansuit,dress,skirt,coat,blanket,lhaf,curtains,weddingdress,ok,cancel;

Font f= new Font("Times New Roman",Font.BOLD,24);

public SpinnerProblem(){

Creategui();

}

public void Creategui (){

setDefaultCloseOperation(EXIT_ON_CLOSE);

setLayout(new BorderLayout());

setSize(800,600);

upanel =new JPanel();

upanel.setBackground(Color.white);

add(upanel,BorderLayout.NORTH);

lpanel=new JPanel();

//lpanel.setLayout(new GridLayout(1,1));

lpanel.setLayout(new FlowLayout());

lpanel.setPreferredSize(new Dimension(100,50));

lpanel.setBackground(Color.white);

add(lpanel,BorderLayout.WEST);

cpanel=new JPanel();

cpanel.setBackground(Color.white);

cpanel.setLayout(new GridLayout(3,4,5,5));

add(cpanel,BorderLayout.CENTER);

spanel=new JPanel();

spanel.setBackground(Color.white);

add(spanel,BorderLayout.SOUTH);

namefield=new JTextField(10);

namefield.setBackground(Color.white);

namefield.setEditable(false);

namefield.setBorder(BorderFactory.createTitledBorder("Name"));

upanel.add(namefield);

lastnamefield=new JTextField(10);

lastnamefield.setBackground(Color.white);

lastnamefield.setEditable(false);

lastnamefield.setBorder(BorderFactory.createTitledBorder("Last Name"));

upanel.add(lastnamefield);

phonefield=new JTextField(10);

phonefield.setBackground(Color.white);

phonefield.setEditable(false);

phonefield.setBorder(BorderFactory.createTitledBorder("Phone"));

upanel.add(phonefield);

total= new JTextField(10);

total.setEditable(true);

total.setBorder(BorderFactory.createTitledBorder("Total"));

spanel.add(total);

sp=new JSpinner();

sp.setPreferredSize(new Dimension(100,50));

sp.setBackground(Color.white);

sp.setBorder(BorderFactory.createTitledBorder("Quantity"));

lpanel.add(sp);

ok=new JButton("OK");

ok.setFont(new Font("Times New Roman",Font.BOLD,14));

spanel.add(ok);

cancel=new JButton("Cancel");

cancel.setFont(new Font("Times New Roman",Font.BOLD,14));

spanel.add(cancel);

pants=new JButton("Pantalon");

pants.setFont(f);

cpanel.add(pants);

chemise=new JButton("Chemise");

chemise.setFont(f);

cpanel.add(chemise);

mansuit= new JButton("badle");

mansuit.setFont(f);

cpanel.add(mansuit);

womansuit= new JButton("ta2m");

womansuit.setFont(f);

cpanel.add(womansuit);

dress= new JButton("dress");

dress.setFont(f);

cpanel.add(dress);

skirt=new JButton("skirt");

skirt.setFont(f);

cpanel.add(skirt);

coat=new JButton("coat");

coat.setFont(f);

cpanel.add(coat);

blanket=new JButton("hram");

blanket.setFont(f);

cpanel.add(blanket);

lhaf=new JButton("lahf");

lhaf.setFont(f);

cpanel.add(lhaf);

curtains=new JButton("curtains");

curtains.setFont(f);

cpanel.add(curtains);

weddingdress=new JButton("weddingdress");

weddingdress.setFont(f);

cpanel.add(weddingdress);

}

/**

* Invoked when an action occurs.

*/

public void actionPerformed(ActionEvent e) {

//To change body of implemented methods use File | Settings | File Templates.

}

public static void main(String[] args){

SpinnerProblem t = new SpinnerProblem();

t.setVisible(true);

}

}

:)[/nobr]

Aniruddha-Herea at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...
# 9
thanks for all of you for your time and for your help...annihahere, your code was the answer for my problem...thanks alot
fouadka at 2007-7-15 5:05:03 > top of Java-index,Desktop,Core GUI APIs...