Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:04:08+00:00 2026-05-23T18:04:08+00:00

I wrote a class (let’s call it Model.java) that contains a Deque<T> , with

  • 0

I wrote a class (let’s call it Model.java) that contains a Deque<T>, with methods for enqueuing and dequeuing items. Now I’m trying to tie this to a GUI JList. I’m baffled by how to somehow use my “model” data — the Deque — as a DefaultListModel that JList wants. I’m still struggling to really get OO concepts, as they apply to GUI programming. DefaultListModel documentation states:

This class loosely implements the java.util.Vector API, in that it implements the 1.1.x version of java.util.Vector, has no collection class support, and notifies the ListDataListeners when changes occur. Presently it delegates to a Vector ….

Is there some way to get the DefaultListModel to use my Deque<T> instead of a Vector, thus allowing my Model.java code to remain largely unchanged while providing all the listening/notifying behavior for free? Or do I have to rewrite Model.java to use a DefaultListModel instead of Deque<T>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:04:09+00:00Added an answer on May 23, 2026 at 6:04 pm

    Notice that the JList constructor takes a ListModel (an interface), not a DefaultListModel (an implementation). This is an OO principle (Contract) specifying that JList can use ANY object that happens to implement the ListModel interface. From the Java tutorial on Object Oriented Programming Concepts:

    An interface is a contract between a class and the outside world. When
    a class implements an interface, it promises to provide the behavior
    published by that interface.

    Since ListModel has only four methods, it should be very easy for your class to implement them and delegate the operations to your internal Deque. Your class should be declared as

    public class Model implements ListModel
    {
         ....
    

    and will contain four additional methods that implement the methods of ListModel. The implementations can do whatever you need under the covers, but must adhere to the definition of ListModel and whatever behavior is specified as part of the ListModel contract, in the JavaDoc.

    Once you have done this, you can construct a JList passing an instance of your class Model to the constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We wrote a small Windows class library that implements extension methods for some standard
I thought it was odd that C# let me call sort on my class
Let's say I wrote a pretty simple class called ValueFinder that looks like this:
So, let's say I want to write a class that operates on different kinds
Here's a Django model class I wrote. This class gets a keyerror when I
I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
For my project I wrote a small config class that loads its data from
I wrote a program in Java 6.0, but it turns out that some of
I wrote a function that looks like this: - (void)changeText:(NSUInteger)arrayIndex; Let's just say that's
I have three tables. Let's call them a, b, and a_to_b. a_to_b contains (among

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.