From 36eca751fdca4323554461327ee7966bcf649ab9 Mon Sep 17 00:00:00 2001 From: SwiftFalcon Date: Sun, 4 Nov 2018 13:27:28 +0300 Subject: [PATCH 1/2] Add JTextArea and JScrollPane components with comments --- src/editor/TextEditor.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/editor/TextEditor.java b/src/editor/TextEditor.java index 228c84b..0be7558 100644 --- a/src/editor/TextEditor.java +++ b/src/editor/TextEditor.java @@ -2,10 +2,24 @@ import javax.swing.*; +//A simple JTextArea component + public class TextEditor extends JFrame { + //constructor - initializing a JTextArea component public TextEditor() { + JTextArea area = new JTextArea(); //constructor of the JTextArea component. + JScrollPane spane = new JScrollPane(area); //make the text scrollable + + area.setLineWrap(true); //makes the lines wrapped if they are too long to fit the text area's width. + area.setWrapStyleWord(true); //lines will be wrapped at word boundaries—white spaces. + + //createLayout(spane); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 300); setVisible(true); + setTitle("JTextEditor"); } + + } \ No newline at end of file From 702b7ecf7cefb943e6554f15b3f58d8b4ff7b096 Mon Sep 17 00:00:00 2001 From: SwiftFalcon Date: Sun, 4 Nov 2018 17:17:12 +0300 Subject: [PATCH 2/2] Add createLayout and fix some issues with Eclipse IDE. --- .gitignore | 1 + src/editor/TextEditor.java | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0bb47a3..7ebc4a7 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ git.properties #IDEA Project Files .idea/ +/bin/ diff --git a/src/editor/TextEditor.java b/src/editor/TextEditor.java index 0be7558..e9f3706 100644 --- a/src/editor/TextEditor.java +++ b/src/editor/TextEditor.java @@ -1,10 +1,17 @@ package editor; +import java.awt.Container; + import javax.swing.*; //A simple JTextArea component public class TextEditor extends JFrame { + /** + * + */ + private static final long serialVersionUID = 1L; + //constructor - initializing a JTextArea component public TextEditor() { JTextArea area = new JTextArea(); //constructor of the JTextArea component. @@ -13,7 +20,7 @@ public TextEditor() { area.setLineWrap(true); //makes the lines wrapped if they are too long to fit the text area's width. area.setWrapStyleWord(true); //lines will be wrapped at word boundaries—white spaces. - //createLayout(spane); + createLayout(spane); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300, 300); @@ -21,5 +28,25 @@ public TextEditor() { setTitle("JTextEditor"); } + private void createLayout(JComponent... arg) { + + Container pane = getContentPane(); + GroupLayout gl = new GroupLayout(pane); + pane.setLayout(gl); + + gl.setAutoCreateContainerGaps(true); + gl.setAutoCreateGaps(true); + + gl.setHorizontalGroup(gl.createParallelGroup() + .addComponent(arg[0]) + + ); + + gl.setVerticalGroup(gl.createSequentialGroup() + .addComponent(arg[0]) + ); + + pack(); + } } \ No newline at end of file