Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create new lines in jlist

 
shaon husain
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49396
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you follow the links included in the comments then you will have your answer.
 
shaon husain
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is exactly why I suggested you read the tutorial because it contains hundreds of example along with explanations of what the code does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic