Hi everyone,

Does anyone have an idea of how to skip a line in a JTextField? In System.out.println, I would normally type n but it didn't work for me when I used it in a textfield:

text1.setText("n"+coloumn[counter]);

where the output displays well as desired excpet that it doesn't skip a line.(Forget about the actual line of code since there is a loop so multiple values are expected in a new line each).

The fact is that I need to know how to skip a line.

Thanks.

By the way, this is the full program:

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
public class Graph {
    public static void main(String args[]){
        JFrame window = new JFrame();
        String alreadythere="";
        int n1,n2,n3,counter=0;
        JPanel frequency = new JPanel();
        JPanel panelOne = new JPanel();
        JPanel panelTwo = new JPanel();
        JTextField text1,text2;
        text1= new JTextField();
        text2= new JTextField();
        int[] coloumn={100,90,80,70,60,50,40,30,20,10,0};


        System.out.println("Please Insert a Number");
        n1=Keyboard.readInt();


        while(counter <11){
                alreadythere=text1.getText();
               if(n1>=coloumn[counter])
               {                   
                  text1.setText(alreadythere+"\n"+coloumn[counter]+"\t*");
                }
               else
               {
                   text1.setText(alreadythere+"\n"+coloumn[counter]);
                }
               counter++;
            }
        text1.setText(alreadythere+"\n\t Student 1");
        text1.setEditable(false);
        panelOne.add(text1);
        window.add(panelOne,BorderLayout.WEST);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setResizable(true);
        window.setVisible(true);
        window.setSize(250,250);
        window.setLocationRelativeTo(null);
        window.setAlwaysOnTop(true);

    }
}

Recommended Answers

All 2 Replies

Check the API documentation for JTextField, you know, the one that starts "JTextField is a lightweight component that allows the editing of a single line of text."
Try JTextArea, "A JTextArea is a multi-line area that displays plain text"

Thanks so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.