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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:27:55+00:00 2026-05-27T21:27:55+00:00

So i am used to building up a JTree by adding DefaultMutableTreeNode ‘s to

  • 0

So i am used to building up a JTree by adding DefaultMutableTreeNode‘s to its model but right now i have a lot of entries that belong to 1 JTree is there a shorter way to do this maybe like you do whit a JList where you can just specify a String table[] = {};

"<html> <b>Shield Hardners</b> </html>", 
"    Ballistic Deflection Array",
"    Explosion Dampening Array",
"    Heat Dissipation Array",
"    Photon Scattering Array",
"<html> <b>Hangar Arrays</b> </html>",
"    Corporate Hangar Array",
"<html> <b>Ship Maintnance Bays</b> </html>",
"    Capital Ship Maintenance Array",
"    Ship Maintenance Array",
"<html> <b>Silos</b> </html>",
"    Biochemical Silo",
"    Catalyst Silo",
"    Coupling Array",
"    General Storage", 
"    Hazardous Chemical Silo", 
"    Silo", 
"<html> <b>Assembly Arrays</b> </html>",
"    Advanced Large Ship Assembly Array",
"    Advanced Medium Ship Assembly Array",
"    Advanced Small Ship Assembly Array",
"    Ammunition Assembly Array",
"    Capital Ship Assembly Array",
"    Component Assembly Array",
"    Drone Assembly Array",
"    Efficient Equipment Assembly Array",
"    Large Ship Assembly Array",
"    Medium Ship Assembly Array",
"    Rapid Equipment Assembly Array",
"    Small Ship Assembly Array",
"<html> <b>Mobile Laboratory</b> </html>",
"    Advanced Mobile Laboratory",
"    Drug Lab",
"    Mobile Laboratory",
"<html> <b>Moon Harvester</b> </html>", 
"    Moon Harvesting Array",
"    Moon Harvesting Array II",
"<html> <b>Reactor Arrays</b> </html>", 
"    Biochemical Reactor Array",
"    Complex Reactor Array", 
"    Medium Biochemical Reactor Array",
"    Simple Reactor Array",
"<html> <b>Refining Arrays</b> </html>", 
"    Intensive Refining Array",
"    Medium Intensive Refining Array", 
"    Refining Array",
"<html> <b>Sov Modules</b> </html>", 
"    Cynosural Generator Array",
"    Cynosural System Jammer", 
"    Jump Bridge", 
"    System Scanning Array",
"<html> <b>Electronic Warfare</b> </html>", 
"    Dread Guristas Ion Field Projection Battery",
"    Guristas Ion Field Projection Battery",
"    Ion Field Projection Battery",
"    Dread Guristas Phase Inversion Battery",
"    Guristas Phase Inversion Battery",
"    Phase Inversion Battery",
"    Dread Guristas Spatial Destabilization Battery",
"    Guristas Spatial Destabilization Battery",
"    Spatial Destabilization Battery",
"    Dread Guristas White Noise Generation Battery",
"    Guristas White Noise Generation Battery",
"    White Noise Generation Battery",
"    Sensor Dampening Battery",
"    Serpentis Sensor Dampening Battery",
"    Shadow Serpentis Sensor Dampening Battery",
"    Stealth Emitter Array",
"    Serpentis Warp Disruption Battery",
"    Shadow Warp Disruption Battery",
"    Warp Disruption Battery",
"    Serpentis Warp Scrambling Battery",
"    Shadow Warp Scrambling Battery",
"    Warp Scrambling Battery",
"    Angel Stasis Webification Battery",
"    Domination Stasis Webification Battery",
"    Stasis Webification Battery",
"<html> <b>Energy Neutralizers</b> </html>",
"    Blood Energy Neutralizing Battery",
"    Dark Blood Energy Neutralizing Battery",
"    Energy Neutralizing Battery",
"    Sansha Energy Neutralizing Battery",
"    True Sansha Energy Neutralizing Battery",
"<html> <b>Hybrid Battery</b> </html>",
"    Large Blaster Battery",
"    Serpentis Large Blaster Battery",
"    Shadow Large Blaster Battery",
"    Medium Blaster Battery",
"    Serpentis Medium Blaster Battery",
"    Shadow Medium Blaster Battery",
"    Small Blaster Battery",
"    Serpentis Small Blaster Battery",
"    Shadow Small Blaster Battery",
"    Large Railgun Battery",
"    Serpentis Large Railgun Battery",
"    Shadow Large Railgun Battery",
"    Medium Railgun Battery",
"    Serpentis Medium Railgun Battery",
"    Shadow Medium Railgun Battery",
"    Small Railgun Battery",
"    Serpentis Small Railgun Battery",
"    Shadow Small Railgun Battery",
"<html> <b>Laser Battery</b> </html>",
"    Large Pulse Laser Battery",
"    Blood Large Pulse Laser Battery",
"    Dark Blood Large Pulse Laser Battery",
"    Sansha Large Pulse Laser Battery",
"    True Sansha Large Pulse Laser Battery",
"    Medium Pulse Laser Battery",
"    Blood Medium Pulse Laser Battery",
"    Dark Blood Medium Pulse Laser Battery",
"    Sansha Medium Pulse Laser Battery",
"    True Sansha Blood Medium Pulse Laser Battery",
"    Small Pulse Laser Battery",
"    Blood Small Pulse Laser Battery",
"    Dark Blood Small Pulse Laser Battery",
"    Sansha Small Pulse Laser Battery",
"    True Sansha Blood Small Pulse Laser Battery",
"    Large Beam Laser Battery",
"    Blood Large Beam Laser Battery",
"    Dark Blood Large Beam Laser Battery",
"    Sansha Large Beam Laser Battery",
"    True Sansha Blood Large Beam Laser Battery",
"    Medium Beam Laser Battery",
"    Blood Medium Beam Laser Battery",
"    Dark Blood Medium Beam Laser Battery",
"    Sansha Medium Beam Laser Battery",
"    True Sansha Blood Medium Beam Laser Battery",
"    Small Beam Laser Battery",
"    Blood Small Beam Laser Battery",
"    Dark Blood Small Beam Laser Battery",
"    Sansha Small Beam Laser Battery",
"    True Sansha Blood Small Beam Laser Battery",
"<html> <b>Missile Battery</b> </html>",
"    Cruise Missile Battery",
"    Dread Guristas Cruise Missile Battery",
"    Guristas Cruise Missile Battery",
"    Torpedo Battery",
"    Dread Guristas Torpedo Battery",
"    Guristas Torpedo Battery",
"    Citadel Torpedo Battery",
"    Dread Guristas Citadel Torpedo Battery",
"    Guristas Citadel Torpedo Battery",
"<html> <b>Projectile Battery</b> </html>",
"    Large AutoCannon Battery",
"    Angel Large AutoCannon Battery",
"    Domination Large AutoCannon Battery",
"    Medium AutoCannon Battery",
"    Angel Medium AutoCannon Battery",
"    Domination Medium AutoCannon Battery",
"    Small AutoCannon Battery",
"    Angel Small AutoCannon Battery",
"    Domination Small AutoCannon Battery",
"    Large Artillery Battery",
"    Angel Large Artillery Battery",
"    Domination Large Artillery Battery",
"    Medium Artillery Battery",
"    Angel Medium Artillery Battery",
"    Domination Medium Artillery Battery",
"    Small Artillery Battery",
"    Angel Small Artillery Battery",
"    Domination Small Artillery Battery"

So this is directly out of my old JList. The JTree should look like this:
Line that contains “html” tag should be a PARENT node and the one whit indent should be CHILD

So it should look like this:

  • Shield Hardners < Parent
  • >>>Ballistic Deflection Array < Child
  • >>>Explosion Dampening Array < Child

I have tried by puting this in a file and parsing it and print out the nodes like so:

public class Env {
    public static void main(String[] args)
    {           
        try {
            Scanner input   = new Scanner(new File("data.txt"));
            String line;
            String sub;
            while(input.hasNextLine())
            {
                line = input.nextLine();

                String subline = line.replace('"', ' ').substring(11).replace("</b> </html> ,", " ").trim().replace(" ", "_");
                if(line.contains("<html>")){
                    System.out.println("DefaultMutableTreeNode " + subline + " = new DefaultMutableTreeNode(" + line.replace(",", " ").trim() + ");");
                } 
            }

        } catch (Exception e) {}
    }
}

Before i finish writing that code is there a simpler way to do this.

  • 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-27T21:27:55+00:00Added an answer on May 27, 2026 at 9:27 pm

    I can only think of using regular expressions to “simplify” the String replace, but even that’s a matter of opinion.

    import java.util.Scanner;
    
    public class TestFoo {
       private static final String FILE_NAME = "data.txt";
       private static final String REGEX = "</?html>|</?b>|\"|,";
    
       public static void main(String[] args) {
          Scanner scan = new Scanner(new File(FILE_NAME));
          while (scan.hasNextLine()) {
             String line = scan.nextLine();
             String newLine = line.replaceAll(REGEX, "").trim();
             if (line.contains("html")) {
                System.out.println("Default Mut: " + newLine);
             } else {
                System.out.println("\t" + newLine);
             }
          }
       }
    }
    

    You’ll need try/catch of course, and shouldn’t ignore the catch block. This will also remove commas inside of the quotes and so is not ideal. There are Java libraries available online for download that allow very clean parsing of comma-delimited files.

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

Sidebar

Related Questions

We have a series of scripts that are used when building Apache. Specifically these
I'm new to building jQuery plugins. I have seen and used a lot of
I have an msbuild project file that is used for building several C++ projects
I have a simple class ExcelStringBuilder. Its used to build a string that can
we are building product that can be used by other systems. As we have
I'm building an application that is used by several different customers. Each customer has
I'm building a generic ASP.NET server control that has an attribute used to specify
What techniques should be used if building UNC paths dynamically, such that to constrain
I am building a library that will be used in several Python applications. It
I used to have the following rule in my .htaccess while building a website:

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.