Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a text box that user can input a large amount of text into

Tags:

java

swing

I'm currently doing a Java assignment as a computer science fresher. As a part of that assignment I'm trying to bring up a secondary frame that the user can write UML code into which will then be passed into my main application and then into a class diagram.

The bit that I'm stuck with is that the JTextBox that I have put into this secondary frame is the size I want it to be, however the writing starts in the middle and does not change to a new line when it gets to the other size of the frame.

This is the image of what is currently happening:

Image of output]![The output of my current code

Code

And this is the code that I currently have for this class if it's needed.

package classdesign;
import java.awt.*;

import javax.swing.*;

 public class ClassCreation extends JFrame {

private JFrame frame;
private JLabel instructionlabel;
private JTextField inputUML;
private JButton upButton;
private String Message;

 public void ClassCreation(){

   frame = new JFrame();
   frame.setSize(300, 400);
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setTitle("Class Design");

   JPanel CreationPanel = new JPanel();
   CreationPanel.setLayout(new BorderLayout());

   instructionlabel = new JLabel("Fill Class details in using UML");
   CreationPanel.add(instructionlabel,BorderLayout.NORTH);

   inputUML = new JTextField("",20);
   CreationPanel.add(inputUML,BorderLayout.CENTER);

   frame.add(CreationPanel);
 }

   public Frame getFrame() {
       return frame;
   }
}

So, to summarise what I was hoping somebody could tell me how to do is to get the text input from the user to start in the top left and change to the next line when it gets to the far right, like any normal text editor etc...

like image 810
DanMc Avatar asked Dec 05 '22 17:12

DanMc


1 Answers

use JTextPane or JEditorPane. Sample can be found at http://docs.oracle.com/javase/tutorial/uiswing/components/editorpane.html

like image 132
Pragalathan M Avatar answered May 18 '23 15:05

Pragalathan M