Setting the displayed text in a JList

I have created a JList by passing it a class that implements the interface ListModel (thank you, Gita Weiner). When the JList is displayed, it shows a cryptical representation of the entries in the class. For example: leeftijd.Persoon@6190b689. (Each entry in the list is an object of type Persoon). How can I show (some of) the attributes of each Persoon object? Class Persoon has attributes First Name and Last Name. I would like to displat that information in the form 'Last Name, First Name'.
The code looks like this:
public class LeeftijdList extends JFrame {
     LeeftijdList(Personenlijst eenPersonenLijst) {
          super("Leeftijd");
          setSize(300, 300);
          JPanel pane = new JPanel();
          FlowLayout lm = new FlowLayout();
          pane.setLayout(lm);
          JList dataList = new JList(eenPersonenLijst);
          JScrollPane scrollPane = new JScrollPane(dataList);
          scrollPane.getViewport().setView(dataList);
          pane.add(scrollPane);
          setContentPane(pane);
     public static void main(String[] arguments) {
          Personenlijst lijst = new Personenlijst();
          lijst.init();
          JFrame frame = new LeeftijdList(lijst);
          ExitWindow exit = new ExitWindow();
          frame.addWindowListener(exit);
          frame.show();
}Note: I don't really understand the line scrollPane.getViewport().setView(dataList). I took it from a code snippet in the API specification.

The default renderer of JList simply uses the toString() method of the Object in the list. What you see is the the default toString() implementation of the Object class which I believe is the memory address of the Object.
Solution. Implement the toString() method in your Object or provide a custom renderer for the JList.
This posting shows both of the above concepts for a JComboBox althought the concept is exactly the same:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=613731

Similar Messages

  • How do I set the default text in a bound textbox?

    How do I set the default value of a bound textbox when the AddNewItem button on the MenuStrip is clicked?
     I have the following code (see below), but for some reason it does work when I put the code in the
    AddNewItem_Click event; however, it does work if I put it in the
    Form's Load Event. The statement in question is Me.txtBusUsagePct.Text = 100.
    What am I doing wrong? Why can't I set the default text in the AddNewItem_Click
    event?
       Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
    Me.txtBusUsagePct.Text = "100"
       End Sub
    BobV365

    Hello,
    Here I am using mocked up data but the important thing is after loading the data. Requires on the form a BindingNavigator and two text boxes.
    Public Class Form1
    WithEvents bsData As New BindingSource
    Private Sub Form1_Load(
    ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles MyBase.Load
    Using MockedData As New DataTable()
    MockedData.Columns.AddRange(New DataColumn() _
    New DataColumn("PartName", GetType(String)),
    New DataColumn("partqty", GetType(Int32))
    MockedData.Rows.Add(New Object() {"Part A", 100})
    MockedData.Rows.Add(New Object() {"Part 99", 34})
    MockedData.Rows.Add(New Object() {"Part B", 4})
    bsData.DataSource = MockedData
    End Using
    CType(bsData.DataSource, DataTable).AcceptChanges()
    BindingNavigator1.BindingSource = bsData
    TextBox1.DataBindings.Add("Text", bsData, "Partname")
    TextBox2.DataBindings.Add("Text", bsData, "partqty")
    End Sub
    Private Sub bsData_AddingNew(
    ByVal sender As Object,
    ByVal e As System.ComponentModel.AddingNewEventArgs) _
    Handles bsData.AddingNew
    Dim dv As DataView = TryCast(bsData.List, DataView)
    Dim rv As DataRowView = dv.AddNew()
    rv("PartName") = "(new)"
    rv("partqty") = 0
    e.NewObject = rv
    bsData.MoveLast()
    End Sub
    End Class
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile
    but do not reply to forum questions.

  • How to set the default text in an input box or a label to be a predefine, multiline text

    how to set the default text in an input box or a label to be a predefine, multiline text. In other words how to break the line in the code of a text box.
    thank you

    There are a couple of ways of doing this:
    If you're editing on the canvas, press Shift + Enter.
    If you're working in Express View (see lower right hand corner of Project Siena), you'll need to copy a hard return from another app such as Notepad.
    I believe a better implementation of hard returns are in the list of requested functionality that you can find here:
    https://social.technet.microsoft.com/Forums/en-US/2e1f9446-56b2-419a-9c17-7037d2cd6146/from-the-community-overview-of-requested-additional-functionality?forum=projectsiena
    Thor

  • How to set the display size of the PDF - in percent?

    Hi, I wonder if anyone knows if it is possible to set
    the display size of the PDF document, so that it always
    shows in, let´s say 100%, in the viewers browser window?
    Much grateful for any help!
    /Anni

    In Acrobat, under Document Properties (Ctrl+D), you can edit the Initial
    View settings, including the zoom level.

  • Setting the display name in a message

    Hello for the following code:
    String from = "[email protected]";
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    I'd like to set the display name, i.e.
    "A Message From Foo"
    However I did not see a msg.setDisplayName() method... is there any way to do this?
    As a working example, amazon sends an email with a return address of [email protected], but the display name is 'Amazon Payments' which looks a lot nicer for the customer. I'd like to do the same.
    Thanks

    Solution is:
    new InternetAddress(email_address, display_name);

  • How to extract the 'display text' of the URLs?

    Hi,
    I want to extract the 'display text' of a link inside an html page? I am using HTML Toolkit class and the getAttribute method...How can i do that since the text is out of 'Attribute'. How to get this text?
    Thanx in advance

    You should try passing the input stream to a Scanner or a BufferedReader and that way you should be able to read in lines of text.
    HttpURLConnection a = null;
              URL b;
              Scanner in = null;
              try {
                   b = new URL("http://www.google.com");
                   a = (HttpURLConnection) b.openConnection();
                   in = new Scanner(a.getInputStream());
                   while(in.hasNext())
                        System.out.println(in.nextLine());
              } catch (Exception e) {
                   e.printStackTrace();
              }Edited: Something like the above.

  • [svn] 3148: You can now use CSS styles to set the default text format for TextView.

    Revision: 3148
    Author: [email protected]
    Date: 2008-09-08 15:01:15 -0700 (Mon, 08 Sep 2008)
    Log Message:
    You can now use CSS styles to set the default text format for TextView. It no longer has any formatting properties. It supports the entire set of Gumbo text format styles.
    SkinnableComponent and Group now also support all these styles. However, skins such as ButtonSkin, TextInputSkin, and TextAreaSkin continue for now to specify instance styles on their TextBox, TextGraphic, and TextView, in order to give them a Gumbo look rather than a Halo look. So if you try setting, for example, the fontSize on the Application, it doesn't yet affect the text format of a Button, TextInput, TextArea, etc. unless you remove the instance style in the skin.
    Reviewer: Glenn
    Bugs: -
    QA: Lots of new stuff to test!
    Doc: No
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/component/TextArea.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/component/TextInput.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/component/TextView.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/core/Group.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/core/SkinnableComponent.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/TextBox.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/TextGraphic.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/graphicsClasses/TextGraphicEle ment.as

    Nevermind guys - I did it using the 'rb_on.selected' command on the "on" radio button if the .txt file variable was "on", else the "off" radio button is selected.
    Thanks for taking a look though!
    Shaun

  • How to set the DISPLAY variable to run admsi.pl?

    Dear Experts,
    I'm trying to patch Oracle apps R12 using admsi.pl.
    hostname: black
    APPS db: VIS
    But I keep getting the error:
    Please set the DISPLAY variable and re-run this script
    This is what I did:
    VIS database and listener are already running.
    login to the linux server as unix user: applmgr
    cd /oapps/applmgr/VIS/apps/apps_st/appl/
    . APPSVIS_black.env
    cd /oapps/applmgr/VIS/apps/apps_st/appl/ad/12.0.0/bin/
    admsi.pl
    Invoking Oracle Patch Application Assistant....
    Please set the DISPLAY variable and re-run this script
    huh ?
    set | grep -i "display"
    DISPLAY=:0.0
    set | wc
    435 486 25235
    I notice that there are 36 .env files!
    For applmgr alone!!
    find /oapps/applmgr/ -type f -name "*.env" | wc
    36 36 2626
    For oracle, there are another 7 .env files!
    find /oapps/oracle/ -type f -name "*.env" | wc
    7 7 513
    Did I get the environment (env) file correct?
    Or do I need to run a few more env first?
    If so, which ones?
    What would the order of operations be?
    sqldeveloper has given me problems with Display sometimes.
    But even sqldeveloper works fine.
    What is the secret to get admsi.pl to run in the normal manner?
    Thank a lot!

    Thanks a lot, that worked! So the perl script was wrong.
    In the meantime, I had done this, and it seemed to work:
    admsi.pl -debug
    Gathering Information..
    Enter the patch_top : /oappsinstall/update12.1.1/7303030
    Enter the APPS user password:
    Logfile for this session is located at admsi.log
    Generating installation instructions for patch 7303030..
    Updating database....
    install_7303030.html generated successfully
    install_7303030.txt generated successfully
    cat /oapps/applmgr/VIS/apps/apps_st/appl/ad/12.0.0/bin/admsi.log
    Executing begin :value := ad_manual_step_object.is_step_already_done('per_hrglobal','120.2.12010000.1'); end;
    Generating installation instructions for patch 7303030..
    Updating database....
    install_7303030.html generated successfully
    install_7303030.txt generated successfully
    Performing final cleanup..
    Do you think this worked ok?
    Thanks again!

  • Set the display in UNIX

    Hi
    I need to access SDM to deploy the Java patch  ( we have X manger enterprise 3)
    We try to set the display in UNIX
    sb2adm> DISPLAY=10.211.146.141:0.0
    sb2adm> export DISPLAY
    sb2adm> set |grep DISPLAY
    DISPLAY=10.211.146.141:0.0
    _=DISPLAY
    sb2adm>
    sb2adm> xclock
    Error: Can't open display: 10.211.146.141:0.0
    My questions:
    When run the command set |grep DISPLAY it would be show DISPLAY=10.211.146.141:0.0
    But in my case it show DISPLAY=10.211.146.141:0.0
    _=DISPLAY
    Thanks so much for your help!!!!
    I would greatly appreciate
    Regards
    Naveen

    Hi ,
    Your shell is ksh (Korn Shell) yout have run export command.
    > sb2adm>setenv DISPLAY 10.211.146.141:0.0
    > -ksh93:: not found
    >
    > Note: one of my college who in onshore he can able to access.as per below command
    >
    > sb2adm> DISPLAY=xxxxxxxxx:0.0
    > sb2adm> export DISPLAY=xxxxxxxxx:0.0
    > sb2adm> set |grep DISPLAY
    > sb2adm > xclock
    You can also use same it will work.
    OR
    sb2adm> DISPLAY=xxxxxxxxx:0
    sb2adm> export DISPLAY=xxxxxxxxx:0
    sb2adm> set |grep DISPLAY
    sb2adm > xclock
    Thanks
    siva

  • How can I set the caption text of picture controls inside an array or how can I choose which array element is assigned using the array elements caption text property.

    I have 8 picture controls inside an array and I would like to set the caption text of these controls.
    I have used the property node of the array and used the array elements property caption text to set the text.
    The problem is however that I set the same text to all the picture controls inside the array.
    My question is how to set caption text of specific elements (Picture control) that I have so far only been able to access using the array elements caption text property.

    Some more help
    1 You could use the caption of the array and place it in front of the selected picture and update that using property nodes.
    2 Like Norbett said if you use a cluster of pictures then their caption can be updated individually.
    Here is a an example that demonstrates the above
    David
    Attachments:
    Modify the Captions Of Pictures.vi ‏83 KB

  • Setting the tab text color in JTabbedPane

    How do I set the text color of tabs? I have to make the text color of one tab to blue and the other tab text color to red. Thanks.

    I tried giving the below but text color is the default it did not change. 'this' is the JTabbedPane. Any other suggessions? Thanks.
    this.setForegroundAt(0,Color.blue);
    this.setForegroundAt(1,Color.red);

  • Setting the display to binary

    Does anyone know how to set the CWIMAQViewer Palette to binary using C++? I know how to do it in Visual Basic, but I can't figure it out in C++. I need to do it programatically. Thanks in advance.

    To Set the viewer to binary:
    m_cViewer.GetPalette().SetType(4096);
    I don't know where 4096 is defined...
    To Set the viewer to grayscale:
    m_cViewer.GetPalette().SetType(2048);
    Again, I don't know where this is defined. To get these values I just inserted the line,
    long paletteType=m_cViewer.GetPalette().GetType();
    and ran the debugger to see what it set paletteType to when I changed the palette using the viewer's palette menu.

  • How to set the display ratio of master and detail view

    Currently, I use SplitApp that contain the master and detail view. And I would like to show the master view on the left half and detail view on the right half. Is there any proper way to adjust this?
    Thank you in advance.

    You can set the width ratio by adding css. Check this,
    http://jsbin.com/dakir/1

  • How to set the "Purpose" text on an Activity?

    Hi,
    I want to create Activities via API. In the UI I see there the fields Name and Purpose. I know how to set the name. But how do I set the purpose via API?
    Thanks, Dieter

    Hi,
    ok, I figured it out: you need a <purpose>.....</purpose> tag in the create XML. I put it as a child node to the <activity> tag. Works fine. Well, it is not described in the API description. There it talks only about the <activity> tag, or i completely overlook the obvious.So, next question: is there a complete scheme description available? Would be quite helpful.
    Regards, Dieter

  • How do I set the display font in TB31.3?

    I would like to see all of my incoming messages displayed as plain text in the same font. Old versions of TB were able to do this. After updating to 31.3, fonts of incoming messages are all different sizes and styles and changing Preferences doesn't help. How can I set them to a single size/style?

    I've checked and unchecked everything I can think of, and it doesn't seem to help. Unless it's just that incoming messages are HTML but that doesn't seem to be the case, and it also seems like there was a big change in this behavior as soon as I updated to 31.3.

Maybe you are looking for

  • MIRO - Posting with trans.type 159 not possible (No acquisition posted)

    Hi all, I have a case where an asset PO was created with multiple account assignment in one line item.  For example, purchase 10 pc of printer with 10 asset numbers specified in the account assignment tab.  By standard SAP, the GR is non-valuated. Th

  • Keep hp 6700 in good shape: automatic print quality diagnostic page every week?

    Hi all, I've recently bought the HP Officejet 6700 Premium, and I'm concerned about keeping it in good condition, since I had to replace my previous canon printer because of a stuck printhead (the photo black one, I didn't used it for a long time). S

  • Usb port not working after yosemite update please help

    ive got an early 2011 macbook pro i5. and one of my usb stopped working. if i reset my  computer it works for a while and then stops again. all these after yosemite update please i really need help on this.. and also when ever im in the middle of som

  • Watch video problems: iphone 4s

    Im trying to watch a mp4 clip on my iphone 4s through my browser, evrytime i go to click on play i get this message come up: 'This video could not be loaded, either because the server or network failed or because the format is not supported' I am abl

  • Wildcard search support in XPath

    Hi all, I am using XPath in querying XML file. My application uses an XML file as a database. I am having a search portal in which user can give wildcard search like name = "M*" etc. As I am using internally XPath to read a particular NodeList from X