Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resizing components

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya!
I'm trying to design a UI using togglebuttons, textfields and comboboxes, ideally i'd like them to all have the same dimensions, but i can't figure out how to do this. The setPreferredSize doesn't seem to have any effect on these components, but works fine with the JButton component. Any ideas as to where i'm going wrong?
TIA
 
Lori Battey
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private Container contentPane;
//to hold dynamic lists
Vector products = new Vector();
Vector invoices = new Vector();
Vector lineItems = new Vector();
DefaultComboBoxModel customers = new DefaultComboBoxModel();

//data containers for lists
JList prodList = new JList(products);
JList invList = new JList(invoices);
JList invProdList = new JList(lineItems);

//so windows will scroll
JScrollPane prodScroll = new JScrollPane(prodList);
JScrollPane invScroll = new JScrollPane(invList);
JScrollPane invProdScroll = new JScrollPane(invProdList);

//labels for windows
JLabel prodLbl = new JLabel();
JLabel invLbl = new JLabel();
JLabel invProdLbl = new JLabel();

//data options buttons
//for product window
JButton creProd = new JButton();
JButton editProd = new JButton();
JButton remProd = new JButton();

//for invoice window
JButton creInv = new JButton();
JButton editInv = new JButton();
JButton remInv = new JButton();

//for invoice lineitems
JButton addItem = new JButton();
JButton remItem = new JButton();();
public void initComponents()
{
try
{
//contentpane
contentPane = this.getContentPane();
contentPane.setLayout(null);
this.setBounds(150, 50, 500, 500);
this.setTitle("Products and Invoices/Entry and Maintenance");

//labels for windows
prodLbl.setText("Products");
invLbl.setText("Invoices");
invProdLbl.setText("On this Invoice");

//data options buttons
//for product window
creProd.setText("Create");
editProd.setText("Edit");
remProd.setText("Remove");

//for invoice window
creInv.setText("Create");
editInv.setText("Edit");
remInv.setText("Remove");

//for invoice lineitems
addItem.setText("Add new Item");
remItem.setText("Remove Item");

//for JDialogs
btnDelete.setText("Confirm Delete");

//add to contentpane and locate
contentPane.add(prodLbl).setBounds(55, 30, 75, 25);
contentPane.add(prodScroll).setBounds(15,75, 140, 300);
contentPane.add(invLbl).setBounds(210, 30, 75, 25);
contentPane.add(invScroll).setBounds(170, 75, 150, 300);
contentPane.add(invProdLbl).setBounds(355, 30, 85, 25);
contentPane.add(invProdScroll).setBounds(335, 75, 140, 300);
contentPane.add(creProd).setBounds(15,388,75,25);
contentPane.add(editProd).setBounds(95,388,60,25);
contentPane.add(remProd).setBounds(40,418,90,25);
contentPane.add(creInv).setBounds(175,388,75,25);
contentPane.add(editInv).setBounds(255,388,60,25);
contentPane.add(remInv).setBounds(200,418,90,25);
contentPane.add(addItem).setBounds(345,388,120,25);
contentPane.add(remItem).setBounds(345,418,120,25);

This is what I do....null layout and .setBounds. This gives you full control over placement and size.
Lori
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic