JTree
をモデルに追加してDefaultMutableTreeNode
を追加することに慣れていましたが、今は1に属しているエントリがたくさんありますJTree
これはもっと簡単な方法ですあなたはちょうどそう、これは私の古いJList
から直接であるString table[] = {};
JTree、たくさんのエントリー
"<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"
を指定することができJList
を聖霊降臨祭です。 JTree
は次のようになります。
- シールドHardners <親 :だから、それは次のようになります。「HTML」タグを含む ラインは、親ノードである必要があり、1つの聖霊降臨祭のインデントはCHILD
- >>>弾道偏向アレイ<子供
- >>>爆発湿アレイ<子供
する必要があります
私はファイルでこれをputingし、それを解析してみましたので、同様のノードを印刷しています
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) {}
}
}
私はそのコードを書き終える前に、これを行うための簡単な方法があります。
なぜそれをHTMLと見なしてはいけないのか、独自の魔法/変換を適切なデータ構造にしてください。 –
@OmarIthawi:有効なHTMLファイルではなく、一部の行にHTMLマークアップのあるカンマ区切りのファイルがあるためです。 –
JListで配列を使用する場合は、配列にエントリを追加するためのループを作成する必要があります。そこで、あなたのコードには、TreeModelに直接エントリを追加するループがあります。なぜ簡単な方法があると思いますか?配列を使用する際に余分なオーバーヘッドを必要としないため、モデルに直接データを追加する方が効率的です(もっと短くなります)。しかし、あなたの質問に答えるために、配列を受け入れるコンストラクタはありません。 – camickr