my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes create new lines in jlist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "create new lines in jlist" Watch "create new lines in jlist" New topic
Author

create new lines in jlist

shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
code:


out put in jlist, eventhough 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
i have tried using html but dont seem to work.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38810
    
  23
I always thought a JList had one line per item. Go through that link; it has some little examples in, and also a link to the Java Tutorials. If those don’t help, please ask again
shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
Campbell Ritchie wrote:I always thought a JList had one line per item. Go through that link; it has some little examples in, and also a link to the Java Tutorials. If those don’t help, please ask again


it is still one item just seperate into many lines, i was told
would do the job in Jlabel, but it didnt, now another tells me cellRender would do it, but after many hours i still dont understand what it actually does or how to use it.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
You were given an answer to this question when you asked it yesterday: create-new-lines-in-jlist.

We don't appreciated spending time answering the same question twice.
shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
Rob Camick wrote:You were given an answer to this question when you asked it yesterday: create-new-lines-in-jlist.

We don't appreciated spending time answering the same question twice.


i didnt noe that coderanch and stackoverflow is created by same person. also there is no answer to it, only 2 COMMENTS, which didnt solve the problem,
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
If you follow the links included in the comments then you will have your answer.
shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
Rob Camick wrote:If you follow the links included in the comments then you will have your answer.

this is all my add to jlist code simplified
this is what i get



when i add this



but if i do this



i have no idea why its doing that

thanks for reading
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
but if i do this


And that is the answer to your question. That is how you solve your problem by using HTML.

i have no idea why its doing that


Because the default renderers in Swing use a JLabel to render the text.
shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
SOLVED


after many hours now i need to code to add an image icon to it any idea or do i have to create new topic
shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
Rob Camick wrote:
but if i do this


And that is the answer to your question. That is how you solve your problem by using HTML.

i have no idea why its doing that


Because the default renderers in Swing use a JLabel to render the text.


TBH i have no idea what your saying, not trying to be rude, ive only started programming, im below a beginneer level.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
Read the JList API and follow the link to the Swing tutorial title "How to Use Lists", where you will find a section on renderers.

I suggest you read the whole tutorial, not just the section on JLIsts. Look at the table of contents to see all the different sections. At a minimum you should read the tutorial BEFORE posting a qustion on the forum so you have some basic knowledge and can understand what we suggest. We don't have time to explain all the concepts. We expect you to do some basic learning on your own. So "I'm a beginner" is no excuse.
shaon husain
Ranch Hand

Joined: Mar 20, 2013
Posts: 37
Rob Camick wrote:Read the JList API and follow the link to the Swing tutorial title "How to Use Lists", where you will find a section on renderers.

I suggest you read the whole tutorial, not just the section on JLIsts. Look at the table of contents to see all the different sections. At a minimum you should read the tutorial BEFORE posting a qustion on the forum so you have some basic knowledge and can understand what we suggest. We don't have time to explain all the concepts. We expect you to do some basic learning on your own. So "I'm a beginner" is no excuse.


personally i dont like reading text, i like looking at examples of full codes and understanding whats happening, but i do read it sometimes

thanks
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
That is exactly why I suggested you read the tutorial because it contains hundreds of example along with explanations of what the code does.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: create new lines in jlist