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 6718351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:31+00:00 2026-05-26T08:57:31+00:00

I have two views (JPanel) that uses the same domain object. My domain object

  • 0

I have two views (JPanel) that uses the same domain object. My domain object contains a ObservableList.

The ObservableList is a LinkedList

private ObservableList<MyObject> listMyObject = ObservableCollections.
    observableList(Collections.synchronizedList(new LinkedList<MyObject>()));

In my two views I to do some calculation each time an element is added to the list

protected class MyListDataListener implements ObservableListListener {
   public void listElementsAdded(ObservableList list, int index, int length) {
   MyObject obj = (MyObject)list.get(index);
   Poin2D location = obj.getObjLocation();
   location.setLocation(location.x + (time / getWidth()), location.y);
   obj.setObjLocation(location);
}

The problem I have is that as both views use the same list each time one element is added to the list the location is updated two times the object that is moving in the view finish its animation two times faster. I would like it to be updated only one time for each element added.

public class MyFrame extends JFrame {
public MyFrame() {
View view1 = new View(domainObject.getMyDataList());
View view2 = new View(domainObject.getMyDataList());
}
}

public class View extends JPanel {
private ObservableList<MyObject> listMyObject;
private ObservableList<MyObject> otherList = ObservableCollections.
    observableList(Collections.synchronizedList(new LinkedList<MyObject>()));

public View(ObservableList<MyObject> listMyObject) {
this.listMyObject = listMyObject;
listMyObject.addListListener(new MyListDataListener());
}

protected class MyListDataListener implements ObservableListListener {
   public void listElementsAdded(ObservableList list, int index, int length) {
otherList.add((MyObject)list.get(index));
for(MyObject obj : otherList) {
Poin2D location = obj.getObjLocation();
   location.setLocation(location.x + (time / getWidth()), location.y);
   obj.setObjLocation(location);
}
}

If i don’t create view2, everything is working fine. With view2 created each time an element is added each view iteratate the list and change the location of my object two times instead of one time.
Thank you for help.

  • 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-26T08:57:32+00:00Added an answer on May 26, 2026 at 8:57 am

    Actually, I don’t understand what you expect:

    • you have a master list (myListData)
    • you have two listeners on that master list
    • you have two copies of that list (otherList) containing the same instances as the master
    • on receving an add, each of the two listeners manipulates the elements in the the copy: those elements are the same instances as in the master, so they manipulated twice ..

    To solve, do the manipulation of the elements once outside of the view, f.i. by keeping the listener outside:

    // frame
    getDataList().addListener(....);
    new View(getDataList());
    // view
    ... do nothing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tabbar items(views) that use the same data, whats the best solution
I have two views that I would like to combine into one. The first
I have a Delphi 7 application that has two views of a document (e.g.
I have an app that has a centre view with two views off to
Setup: I have two views that I need to respond to the touch event,
I have two Views that are positioned on top of each other. The first
I have two different views that makes upwards of 500 partial view calls each
i have two views and one viewcontroller: one contains UIImageView with image, second have
I have two overlapping custom views that need to both receive touch events (e.g.
I have two views which will both use the same Controller method: //webServiceController.cs //The

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.