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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:10:51+00:00 2026-06-04T05:10:51+00:00

I have a class with several member variables, one of which is a DefaultTableModel.

  • 0

I have a class with several member variables, one of which is a DefaultTableModel. My constructor for the class uses a MySQL ResultSet to populate the DefaultTableModel. I would like to generate an exact copy of the DefaultTableModel and store it as another member variable within my class, so I can edit a copy of the variable within my class while maintaining a copy of the original variable.

Below is an outline of my class.

public class MyClass() {

    int i;
    Boolean b;
    DefaultTableModel model;
    DefaultTableModel model2;

    MyClass(ResultSet myRS) {
        //code to initialize i,b,model;
        //code to clone model and save as model2;
        //code to modify model2;
    }

    public DefaultTableModel getModels(String s) {
        //code that returns model or model2;
    }

}

I have been doing some reading but haven’t figured out how to make an exact copy of a variable within a class. I know I can’t just do model2 = model; since this just copies the references of the variable. I made this mistake and found out that editing model2 would also edit model. Everything I have read about clone makes it seem that it is just used to make a new and identical instance of an entire class. Any advice on how to clone a single variable within a class would be greatly appreciated.

  • 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-06-04T05:10:52+00:00Added an answer on June 4, 2026 at 5:10 am

    Normally if it was your own TableModel subclass rather than DefaultTableModel you could achive this by making your TableModel implement Clonable and get a copy by calling the clone() method.

    As you are working with DefaultTableModel instances, you have to go the other way around and do this:

    Instead of creating a single Object[][] or Vector instance for passing data to the constructor of DefaultTableModel, create two copies of Object[][] or Vector. With these you can create both DefaultTableModel instances with the same content.

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

Sidebar

Related Questions

My User entity class have several member variables (e.g. String firstName) which are persisted
I have a class Person which can have several Homes, each one with one
I have a class that is called regularly by several objects. I would like
I would like to have a class implement operator() several different ways based on
I have several members in my class which are const and can therefore only
I have a Binary-Tree class template with several public and private member functions. When
I have a domain model that contains member variables for two languages, something like
I have a class that contains a private typedef and several member functions: class
I would like to have the mutators (setters) in my class to return this
I have a class containing several properties (all are strings if it makes any

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.