Article 5STN1 Implementing file explorer GUI like one of VS Code. In java.

Implementing file explorer GUI like one of VS Code. In java.

by
xg3571
from LinuxQuestions.org on (#5STN1)
Code:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

class BoxLayoutTest extends Frame {
BoxLayoutTest() {
JPanel explorer = new JPanel();

explorer.setLayout(new BoxLayout(explorer, BoxLayout.Y_AXIS));

// Label showing current path
JLabel currentPath = new JLabel("root/java");
currentPath.setAlignmentX( LEFT_ALIGNMENT );

// add a folder button
JButton addFolder = new JButton("add folder");
addFolder.setSize(10, 5);
addFolder.setAlignmentX(RIGHT_ALIGNMENT);

// add a file button
JButton addFile = new JButton("add file");
addFile.setSize(10, 5);
addFile.setAlignmentX(RIGHT_ALIGNMENT);

// Labels of subdirectories
ArrayList childrens = new ArrayList();
childrens.add(new JLabel("java"));
childrens.add(new JLabel("cpp"));
childrens.add(new JLabel("python"));

explorer.add(currentPath);
explorer.add(addFolder);
explorer.add(addFile);

Object[] labels = childrens.toArray();

for (Object l : labels) {
JLabel label = (JLabel)l;
label.setAlignmentX( LEFT_ALIGNMENT );
explorer.add(label);
}

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

add("West", explorer);
setSize(700, 700);
setVisible(true);
}

public static void main(String[] args) {
BoxLayoutTest win = new BoxLayoutTest();
}
}On the top, showing current path left aligned and
following are buttons off "add folder" and "add file" right aligned
Below are labels sub directories left aligned

But when I run the code, layout become mess. none of code are run as I want like attached picture

I'll be thankful of advice
Attached Thumbnailsattachment.php?attachmentid=37812&stc=1& attachment.php?attachmentid=37813&stc=1& latest?d=yIl2AUoC8zA latest?i=ByouRhmIlsA:Z-1m1KbIMjA:F7zBnMy latest?i=ByouRhmIlsA:Z-1m1KbIMjA:V_sGLiP latest?d=qj6IDK7rITs latest?i=ByouRhmIlsA:Z-1m1KbIMjA:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments