0

code:

String key = stockNo.getText();
String quantityTxt = quantity.getText();
String info = "\n\nName: " + StockData.getName(key) + 
                "\nPrice: £" + (StockData.getPrice(key)) + 
                "\nNumber in stock: " + StockData.getQuantity(key) +
                "\nNumber to buy: " + quantityTxt;
information.append(info);

out put in jlist, i put the \n but dont seem to work

key:33nameTshirtprice: £10.00number in stock:37number to buy:1
key:55nameshirtprice: £5.00number in stock:12number to buy:1

how would i get it as,

key:33
name: Tshirt                 (image will go here)
price: £10
number in stock: 37
number bought 1

ect this will be one element in the list

(sorry cant put images due to rep)

mKorbel
  • 109,107
  • 18
  • 130
  • 305
user2158735
  • 47
  • 2
  • 10
  • Have you tried implementing a custom [`ListCellRenderer`](http://download.oracle.com/javase/7/docs/api/javax/swing/ListCellRenderer.html)? What about using the HTML line break tag, i.e. `
    `?
    – obataku Mar 24 '13 at 23:10
  • Use HTML text. See this question: http://stackoverflow.com/questions/1090098/newline-in-jlabel – Michał Ziober Mar 24 '13 at 23:15
  • @mykhaylo this is what i get when i use html `javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignment.......` i removed the `swingconstant.centre` but same thing. @oldrinb how would i go aroung using `listcellrender` thanks for your contribution – user2158735 Mar 25 '13 at 00:51

0 Answers0