Как отобразить разделенные строки в JOptionpane по размеру пользователя - PullRequest
0 голосов
/ 17 марта 2020

Привет, как я могу отобразить мои разделенные строки в JOptionPane? Мое окно продолжает печатать / показывать мои строки 1 на 1, я хочу, чтобы они печатали / показывали, учитывая размер моего пользователя

    String letters, splitSize;

    letters = JOptionPane.showInputDialog("Enter String: ");
    final int numInLetters = letters.length(); 

    splitSize = JOptionPane.showInputDialog("Enter Split Size");
    int sizeSplit = Integer.parseInt(splitSize);

    if (numInLetters % sizeSplit == 0) {

        JOptionPane.showMessageDialog(null, "The Given String is" + letters);
        JOptionPane.showMessageDialog(null, "The Split String are: ");

        String []in_array;

        in_array = letters.split("");
        for (int i = 1; i <= in_array.length; i++) {


                    //what alternative way to show my split string here given by user's split size
            JOptionPane.showMessageDialog(null, in_array[i-1]);         


         if (i % sizeSplit == 0) {

            JOptionPane.showMessageDialog(null, "");

1 Ответ

0 голосов
/ 17 марта 2020

Я не совсем уверен, что вы пытаетесь достичь sh, но я думаю, что это может быть то, что вы хотите:

String letters = JOptionPane.showInputDialog("Enter String: ");

String splitSize  = JOptionPane.showInputDialog("Enter Split Size");
int sizeSplit = Integer.parseInt(splitSize);

List<String> list = new ArrayList<>();
int idx = 0;
while (idx < letters.length()) {
    int toIdx = Math.min(idx + sizeSplit, letters.length());
    list.add(letters.substring(idx, toIdx));
    idx = toIdx;
}

JOptionPane.showMessageDialog(null, "The Split String are: " + System.lineSeparator() + String.join(System.lineSeparator(), list));
...