Results 1 to 8 of 8
  1. #1
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default DefaultListModel Elements

    Hi,
    Does anybody know which method I can use to set all the elements of the ListModel object to a specific font?
    Thanks.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,727
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by jboy View Post
    Hi,
    Does anybody know which method I can use to set all the elements of the ListModel object to a specific font?
    Thanks.
    A ListModel has nothing to do with the display of its data; it just takes care of the data. It's the JList that has to display the data and because a JList extends from a JComponent it doesn't have to deal with the font used itself.

    kind regards,

    Jos

  3. #3
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default

    I understand but how should I go about setting the font of element of the list?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,727
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by jboy View Post
    I understand but how should I go about setting the font of element of the list?
    If you want to set a different font per cell you have to implement your own ListCellRenderer for that purpose (read the API documentation for an explanation of cell renderers).

    kind regards,

    Jos

  5. #5
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default

    Ok, Thanks.
    I have another question if I have a table and has data as follows, how can I set the font of the string hello?
    Java Code:
    data[1][0] = "hello";
    Thank you

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Strings don't have fonts.

  7. #7
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default

    Does that mean that there is no way that I can change the font of the string "hello"?

  8. #8
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    See reply 6.

    If you need further help then you need to create a SSCCE, that demonstrates the incorrect behaviour.

Similar Threads

  1. Replies: 3
    Last Post: 04-24-2009, 07:28 PM
  2. what does <Elements> mean
    By JordashTalon in forum New To Java
    Replies: 1
    Last Post: 01-31-2009, 11:19 PM
  3. Negative elements
    By swikar.java in forum New To Java
    Replies: 6
    Last Post: 12-15-2008, 05:48 AM
  4. using elements from other classes
    By Camden in forum New To Java
    Replies: 1
    Last Post: 03-21-2008, 08:25 AM
  5. Elements package
    By BlitzA in forum New To Java
    Replies: 0
    Last Post: 12-28-2007, 12:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •