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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:11:39+00:00 2026-06-08T08:11:39+00:00

I have created a table and some buttons to remove/add rows. Problem is, when

  • 0

I have created a table and some buttons to remove/add rows.
Problem is, when I add a new row, I must insert a value in the field name which isn’t already on that table. Let me explain.

Here is the default table:

11

Now imagine i remove Station 3:

22

If i add a new Station, I would want to add a new Station name Station 3 (which is missing on the list) but I am adding a new Station 5 (obviously as my code is not correct).

33

My code for the Add Button action event is as such:

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
    DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
    String s2 = "";
    String s1 = "Station 1 Station 2 Station 3 Station 4 Station 5";
    int tb1rows = jTable1.getRowCount();
    if (tb1rows == 5) {
        // ERROR - MAXIMUM STATION NUMBER
    }
    else {
        for (int i=0; i<tb1rows;i++) {
            s2.concat(jTable1.getValueAt(i,1).toString());
            s2.concat(" ");
         }
        String[] s3=s2.split(" ");
        for (int i=0;i<s3.length;i++) {
            if (s1.contains(s3[i])) {
                System.err.println("contains");
                System.out.println(s3[i]);
            }
        }
        model.insertRow(jTable1.getRowCount(),new Object[] {jTable1.getRowCount() + 1,"Station " + (jTable1.getRowCount()+1),10,false,0,Color.BLACK});
    }
}

What’s wrong with my logic? Is there a better way to handle the problem so that I can get the “Station x” that is missing in that column so that I can re-add it?

Thanks in advance for your answers.

  • 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-08T08:11:40+00:00Added an answer on June 8, 2026 at 8:11 am

    instead of all that string manipulation, you could use set mainpulations:

    HashSet<String> all = new HashSet<String>();
    // then populate all with your 5 station strings (loop)
    HashSet<String> have = new HashSet<String>();
    // then populate all with the contents of your table (loop)
    all.removeAll(have);
    // all now contains the ones that weren't in the table.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some problem.. i have created a dynamic button in a table view.
I have a table where I created an INSTEAD OF trigger to enforce some
I have created a table layout in which my table row height is too
We have created a table with a trigger that updates a ModifiedDate field in
I have created a component for table row and added in to another activity.it's
I have a dynamically created table and in some of the cells i have
I have a table in which i append rows on onclick event, the row
I have defined a table type PL/SQL variable and added some data there. create
I have created table and inserted values as below. create table mytable (id INT,
I have created a table in Visual Studio. That table has two columns. First

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.