• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JList help.

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a JList through IDE. The list have been declared as,

private javax.swing.JList jList1;

now i want to add data to the list, i have a string array in which i have the values, but when i try adding by using the following,

for(int i=0;i<=5;i++)
jList1.add(i,tmpArrya[i]);


no suitable method found for add(int,java.lang.String)
method java.awt.Container.add(java.awt.Component,java.lang.Object,int) is not applicable
(actual and formal argument lists differ in length)
method java.awt.Container.add(java.awt.Component,java.lang.Object) is not applicable
(actual argument int cannot be converted to java.awt.Component by method invocation conversion)
method java.awt.Container.add(java.awt.Component,int) is not applicable
(actual argument int cannot be converted to java.awt.Component by method invocation conversion)
method java.awt.Container.add(java.lang.String,java.awt.Component) is not applicable
(actual argument int cannot be converted to java.lang.String by method invocation conversion)
method java.awt.Container.add(java.awt.Component) is not applicable
(actual and formal argument lists differ in length)
method java.awt.Component.add(java.awt.PopupMenu) is not applicable
(actual and formal argument lists differ in length)

I am not sure of what half of it means either. How will I be able to add the values to the list dynamically??
Any help will be greatly appreciated.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The message is saying that the JList class does not have an add method that takes an int and a String as parameters.
You need to use a different add method (or maybe a different method altogether) to do whatever it is you are trying to do
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How will I be able to add the values to the list dynamically??
Any help will be greatly appreciated.
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JList has a ListModel that contains the actual data. You need to use a ListModel implementation that allows you to dynamically add to it. Check out DefaultListModel.
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob, thanks for the reply. I am kinda hitting a brick wall.
could you provide a simple example?
I have tried the foillowing but it does not seem to display on the jList.



 
Rob Spoor
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your first example you used jList1, now you're using jList2. Are you checking the right JList?
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am sorry.. Yes, I am checking the right fields. When i started the question i used jList1. Then i deleted it from my design, again added a new list which came up as jList2. So the variables are fine.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have created a JList through IDE.


Yes, I am checking the right fields. When i started the question i used jList1. Then i deleted it from my design, again added a new list which came up as jList2.


Dump the visual designer. It's easier to learn to write Swing code yourself.

Visual designers, with their near-unreadable generated code, are not beginners' tools. The learning curve can be steep, and the effort is only worthwhile if you go make a career of developing GUIs.
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Darryl, I hear what you are saying, but building here gives me a bit of advantage. Helps me know know my syntax errors, proper imports. Please could you help me out here??
 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think at this point, this discussion belong in a different forum: to Swing we go!
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Ruban Raj Eugin Francis wrote:


This code should work. Has the jList2 been added to the panel/frame? Also, make sure you have this code before you make the frame visible.

Better, post a SSCCE that demonstrates the problem.
 
Andrew Geroge Alexander
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I got it resolved.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic