import java.awt.Container;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.SwingUtilities;
public class AllLinesGetter extends JFrame {
private void setGui() {
try {
setLocation(0, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = getContentPane();
cp.add(new JList(getStringModel("/x.txt")));
} catch (Exception e) {
e.printStackTrace();
}
}
public ComboBoxModel<String> getStringModel(String resourcePath) {
ComboBoxModel<String> result = null;
try {
URL u = getClass().getResource(resourcePath);
Path p = Paths.get(u.toURI());
java.util.List<String> lines = Files.readAllLines(p,
Charset.forName("UTF-8"));
result = new DefaultComboBoxModel<String>(new Vector<String>(lines));
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
AllLinesGetter f = new AllLinesGetter();
f.setGui();
f.pack();
f.setVisible(true);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.SwingUtilities;
public class AllLinesGetter extends JFrame {
private void setGui() {
try {
setLocation(0, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = getContentPane();
cp.add(new JList(getStringModel("/x.txt")));
} catch (Exception e) {
e.printStackTrace();
}
}
public ComboBoxModel<String> getStringModel(String resourcePath) {
ComboBoxModel<String> result = null;
try {
URL u = getClass().getResource(resourcePath);
Path p = Paths.get(u.toURI());
java.util.List<String> lines = Files.readAllLines(p,
Charset.forName("UTF-8"));
result = new DefaultComboBoxModel<String>(new Vector<String>(lines));
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
AllLinesGetter f = new AllLinesGetter();
f.setGui();
f.pack();
f.setVisible(true);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}