• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Resizing components

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Seriously? That's what you're going with? I prefer this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic