Jak strasznie się chcesz upierać przy formatowaniu JTextArea
to możesz użyć metody format
z klasy String
ale efekt jest mizerny....
package textarea;
import javax.swing.*;
/**
* Created by Rafał on 09.02.2017.
*/
public class Main extends JFrame {
private JPanel panel = new JPanel();
private static JTextArea area = new JTextArea();
private static String[] date1 = {"Ala", "Ola", "Bartek", "Kuba"};
private static String[] date2 = {"Wiola", "Krysia", "Zbyszek", "Kuba"};
public static void main(String[] args) {
Main okno = new Main();
okno.setVisible(true);
okno.setSize(700,700);
okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
okno.initGUI();
for (int i = 0; i < date1.length; i++) {
String format = "%-" + ((i * 10) + 10) + "s";
area.append(String.format(format, date1[i]));
}
area.append("\n");
for (int i = 0; i < date2.length; i++) {
String format = "%-" + ((i * 10) + 10) + "s";
area.append(String.format(format, date2[i]));
}
}
public void initGUI() {
panel.setLayout(null);
area.setBounds(0,0,500,200);
panel.add(area);
setLayout(null);
panel.setBounds(0,0,500,300);
add(panel);
}
}
teoretycznie odległości są równe (mówię o ilości znaków od początku), tyle że spacje są węższe od innych znaków i efekt jest końcowy taki że wygląda to tak jakby nie było to sformatowane.