Hi,

This program has the information I need it to have but instead of going down in a column it goes straight across. Can someone show me where to get the formatting for this kind of code? I tried different things to no avail. Thank you for this and all the other help I have received here at Daniweb.

Thank you,

Lynn Ortiz

public class GUI extends JFrame  {

    private String productName;
    private int    itemNumber;
    private int    unitsInStock;
    private double pricePerUnit;
    private double productValue ;
    private double inventoryValue ;


 private NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); //NumberFormatter
   protected JList list;
       public GUI() {
    super("Swing List with Tab Renenderer");
    setSize(500, 240);
    }
    public GUI ( String productName,  int itemNumber,
          int unitsInStock,  double pricePerUnit){
         Printer [] myPrinters = new Printer[5];
    }
      
    public static void main (String []args){

         Printer [] myPrinters = new Printer[5];

         Printer epson   = new Epson("Epson","A09514", 1, 2, 99.99);
         Printer hp      = new Printer("HP", 2, 3, 149.99);
         Printer brother = new Printer("Brother", 3, 2, 199.99);
         Printer kodak   = new Printer("Kodak", 4, 2, 89.99);
         Printer canon   = new Printer("Canon", 5, 3, 129.99);

    

         DefaultListModel model = new DefaultListModel();
         JList list = new JList(model);
      
                
    Printer[] items = {epson,hp,brother,kodak,canon };

    for (int i=0; i<items.length; i++) {
    model.add(i, items[i]);
        }
JFrame window = new JFrame ();
window.add(list ); JTextArea area = new JTextArea();
    area.setLineWrap(true);
    area.setWrapStyleWord(true);
    area.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

    
        window.setSize( 800, 500 );
        window.setVisible( true );
        window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
     
}

   /**
     * @return the productName
     */
    public String getProductName() {
        return productName;
    }

    public void setProdName(String productName) {
        this.productName = productName;
    }
    /**
     * @return the itemNumber
     */
    public int getItemNumber() {
        return itemNumber;
    }
    /**
     * @param itemNumber the itemNumber to set
     */
    public void setItemNumber(int itemNumber) {
        this.itemNumber = itemNumber;
    }

    /**
     * @return the unitsInStock
     */
    public int getUnitsInStock() {
        return unitsInStock;
    }

    /**
     * @param unitsInStock the unitsInStock to set
     */
    public void setUnitsInStock(int unitsInStock) {
        this.unitsInStock = unitsInStock;
    }

    /**
     * @return the pricePerUnit
     */
    
    public double getPricePerUnit() {
        return pricePerUnit;
    }

    /**
     * @param pricePerUnit the pricePerUnit to set
     */
   
    public void setPricePerUnit(double pricePerUnit) {
        this.pricePerUnit = pricePerUnit;
    }

   
}

If you are refering to you JFrame components you could use the gridBag layout to show them like a column.

For example, i'll set diferent components inside a panel, an then add the panel to JFrame:

...
JPanel panel = new JPanel;
panel.setLayout(new GridBagLayout());
menuPanel.setBounds(0,0, 50, 200);

GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.VERTICAL;
c.weightx = 0.5;

// A column of three levels
c.gridwidth = 1;
c.gridheight = 3;

// Three JButtons

b1 = new JButton("one");
b1.setBounds(0, 0, 50, 30);

b2 = new JButton("two");
b2.setBounds(0, 0, 50, 30);

b3 = new JButton("three");
b3.setBounds(0, 0, 50, 30);

// Grid Bag Layout is like a matrix
// Placing the buttons

c.gridx = 0;
c.gridy = 0;
panel.add(b1,c);

c.gridx = 0;
c.gridy = 1;
panel.add(b3,c);

c.gridx = 0;
c.gridy = 2;
panel.add(b3,c);
...
// And add the panel to the main Frame(or other component)

Anyway, you can find more detailed info on the web.
Greetings

Hi,

Thank you. I cannot use JButtons but this helps regardless. I appreciate it.

lynnajoe

Let me check: you have multiple products each with multiple attributes.
You want to display one line per product, with the attributes in aligned columns.
Is that right?
If so, use a JTable.

Hi,

That's it and thanks I will look into it.

Thank you,

lynnajoe

This article has been dead for over six months. Start a new discussion instead.