1
Topics
JFrame
JTextArea
JScrollPane
Lecture By:- Mr. Akaash
2
Open NetBeans IDE 8.1
Lecture By:- Mr. Akaash
3
Open File Menu
Lecture By:- Mr. Akaash
4
Click on New Project
Lecture By:- Mr. Akaash
5
Select Category “Java”
Lecture By:- Mr. Akaash
6
Select Project Java Application
Lecture By:- Mr. Akaash
7
Click on Next Button
Lecture By:- Mr. Akaash
8
Write Project Name
Lecture By:- Mr. Akaash
9
Create Main Class
Lecture By:- Mr. Akaash
10
Click on Finish Button
Lecture By:- Mr. Akaash
11
What is Jframe?
A frame, implemented as an instance of the JFrame
class, is a window that has decorations such as a
border, a title, and supports button components that
close or iconify the window. Applications with a GUI
usually include at least one frame
Lecture By:- Mr. Akaash
12
Create JFrame
13
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Lecture By:- Mr. Akaash
14
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Lecture By:- Mr. Akaash
15
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Main Function
Lecture By:- Mr. Akaash
16
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Main Function
Class
Lecture By:- Mr. Akaash
17
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Main Function
Class Object
Lecture By:- Mr. Akaash
18
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Main Function
Class Object Keyword
Lecture By:- Mr. Akaash
19
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Main Function
Class Object Keyword Constructor
Lecture By:- Mr. Akaash
20
Coding of JFrame
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class JTextAreaTest {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Built_in Packages of Java
Programming Language
Main Class
Main Function
Class Object Keyword Constructor Value
Lecture By:- Mr. Akaash
21
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object
Lecture By:- Mr. Akaash
22
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method
Lecture By:- Mr. Akaash
23
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width
Lecture By:- Mr. Akaash
24
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Lecture By:- Mr. Akaash
25
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object
Lecture By:- Mr. Akaash
26
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method
Lecture By:- Mr. Akaash
27
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword
Lecture By:- Mr. Akaash
28
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Lecture By:- Mr. Akaash
29
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object
Lecture By:- Mr. Akaash
30
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object Method
Lecture By:- Mr. Akaash
31
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object Method Boolean value
Lecture By:- Mr. Akaash
32
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object Method Boolean value
Object
Lecture By:- Mr. Akaash
33
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object Method Boolean value
Object Method
Lecture By:- Mr. Akaash
34
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object Method Boolean value
Object Method Class
Lecture By:- Mr. Akaash
35
Coding of JFrame
frame.setSize(280, 150);
frame.setLayout(new FlowLayout());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Object Method Width Height
Object Method Keyword Method
Object Method Boolean value
Object Method Value Class Method
Lecture By:- Mr. Akaash
36
Explanation of Previously Used
Methods
setSize(). Method allows you to set the size like Width & height of JFrame
setResizable(). One method for ensuring that a graphical interface looks the way you intend is
to prevent the user from re-sizing it, using this method of JFrame :
setLayout(). Method allows you to set the layout of the container, often a JPanel, to say
FlowLayout(), BorderLayout(), GridLayout(), null layout(), or
whatever layout desired. The layout manager helps lay out the components held
by this container
setDefaultCloseOperation() method is used to specify one of several options for the close
button. Use one of the following constants to specify your choice:
 JFrame.EXIT_ON_CLOSE — Exit the application.
 JFrame.HIDE_ON_CLOSE — Hide the frame, but keep the application running.
 JFrame.DISPOSE_ON_CLOSE — Dispose of the frame object, but keep the application running.
 JFrame.DO_NOTHING_ON_CLOSE — Ignore the click.
If you forget to call setDefaultCloseOperation() you will get JFrame.HIDE_ON_CLOSE by default.
This can be frustrating, because it looks like you have "killed" the program, but it keeps on running,
and you see no frame.
Lecture By:- Mr. Akaash
37
What is JTextArea?
A JTextArea is a multi-line area that displays plain
text. It is intended to be a lightweight component that
provides source compatibility with the
java.awt.TextArea class where it can reasonably do
so.
Lecture By:- Mr. Akaash
38
Add “JTextArea” on Frame
39
Coding of JTextArea
JTextArea textArea1 = new JTextArea(text);
textArea1.setPreferredSize(new Dimension(100, 100));
textArea1.setLineWrap(true);
frame.add(textArea1);
Class Object Keyword Constructor Value
Object Method Keyword Method Width Height
Object Method Boolean value
Object Method Object
Lecture By:- Mr. Akaash
40
Constructors and Description
JTextArea()
Constructs a new TextArea.
JTextArea(Document doc)
Constructs a new JTextArea with the given document model, and defaults for all of the other
arguments (null, 0, 0).
JTextArea(Document doc, String text, int rows, int columns)
Constructs a new JTextArea with the specified number of rows and columns, and the given model.
JTextArea(int rows, int columns)
Constructs a new empty TextArea with the specified number of rows and columns.
JTextArea(String text)
Constructs a new TextArea with the specified text displayed.
JTextArea(String text, int rows, int columns)
Constructs a new TextArea with the specified text and number of rows and columns.
Lecture By:- Mr. Akaash
41
Methods
Modifier and Type Method and Description
void
append(String str)
Appends the given text to the end of the document.
protected
Document
createDefaultModel()
Creates the default implementation of the model to be used at
construction if one isn't explicitly given.
AccessibleContext
getAccessibleContext()
Gets the AccessibleContext associated with this JTextArea.
int
getColumns()
Returns the number of columns in the TextArea.
protected int
getColumnWidth()
Gets column width.
int
getLineCount()
Determines the number of lines contained in the area.
int
getLineEndOffset(int line)
Determines the offset of the end of the given line.
Lecture By:- Mr. Akaash
42
Methods
Modifier and Type Method and Description
boolean
getLineWrap()
Gets the line-wrapping policy of the text area.
Dimension
getPreferredScrollableViewportSize()
Returns the preferred size of the viewport if this component is embedded in a
JScrollPane.
Dimension
getPreferredSize()
Returns the preferred size of the TextArea.
protected int
getRowHeight()
Defines the meaning of the height of a row.
int
getRows()
Returns the number of rows in the TextArea.
boolean
getScrollableTracksViewportWidth()
Returns true if a viewport should always force the width of this Scrollable to
match the width of the viewport.
int
getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Components that display logical rows or columns should compute the scroll
increment that will completely expose one new row or column, depending on
the value of orientation.
Lecture By:- Mr. Akaash
43
Methods
Modifier & Type Method and Description
Int getTabSize()
Gets the number of characters used to expand tabs.
String getUIClassID()
Returns the class ID for the UI.
Boolean getWrapStyleWord()
Gets the style of wrapping used if the text area is wrapping lines.
Void insert(String str, int pos)
Inserts the specified text at the specified position.
protected String paramString()
Returns a string representation of this JTextArea.
Void replaceRange(String str, int start, int end)
Replaces text from the indicated start to end position with the new
text specified.
Void setColumns(int columns)
Sets the number of columns for this TextArea.
Void setTabSize(int size)
Sets the number of characters to expand tabs to.
Void setWrapStyleWord(boolean word)
Sets the style of wrapping used if the text area is wrapping lines.
44
JTextArea with ScrollPane
45
Coding of JTextArea with
ScrollPane
JTextArea textArea2 = new JTextArea(text, 5, 10);
textArea2.setLineWrap(true);
JScrollPane scrollPane = new
JScrollPane(textArea2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.add(scrollPane);
Lecture By:- Mr. Akaash
46
Why JScrollPane used with
JTextArea?
A JTextArea object represents a multiline area for displaying
text. If Text is too large from JTextArea Boundaries(Width,
Height) then You can also put your JTextArea in a
JScrollPane to make it scrollable.
Lecture By:- Mr. Akaash
47Lecture By:- Mr. Akaash

jframe, jtextarea and jscrollpane

  • 1.
  • 2.
    2 Open NetBeans IDE8.1 Lecture By:- Mr. Akaash
  • 3.
    3 Open File Menu LectureBy:- Mr. Akaash
  • 4.
    4 Click on NewProject Lecture By:- Mr. Akaash
  • 5.
  • 6.
    6 Select Project JavaApplication Lecture By:- Mr. Akaash
  • 7.
    7 Click on NextButton Lecture By:- Mr. Akaash
  • 8.
  • 9.
  • 10.
    10 Click on FinishButton Lecture By:- Mr. Akaash
  • 11.
    11 What is Jframe? Aframe, implemented as an instance of the JFrame class, is a window that has decorations such as a border, a title, and supports button components that close or iconify the window. Applications with a GUI usually include at least one frame Lecture By:- Mr. Akaash
  • 12.
  • 13.
    13 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Lecture By:- Mr. Akaash
  • 14.
    14 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Lecture By:- Mr. Akaash
  • 15.
    15 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Main Function Lecture By:- Mr. Akaash
  • 16.
    16 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Main Function Class Lecture By:- Mr. Akaash
  • 17.
    17 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Main Function Class Object Lecture By:- Mr. Akaash
  • 18.
    18 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Main Function Class Object Keyword Lecture By:- Mr. Akaash
  • 19.
    19 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Main Function Class Object Keyword Constructor Lecture By:- Mr. Akaash
  • 20.
    20 Coding of JFrame importjava.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Built_in Packages of Java Programming Language Main Class Main Function Class Object Keyword Constructor Value Lecture By:- Mr. Akaash
  • 21.
    21 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Lecture By:- Mr. Akaash
  • 22.
    22 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Lecture By:- Mr. Akaash
  • 23.
    23 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Lecture By:- Mr. Akaash
  • 24.
    24 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Lecture By:- Mr. Akaash
  • 25.
    25 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Lecture By:- Mr. Akaash
  • 26.
    26 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Lecture By:- Mr. Akaash
  • 27.
    27 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Lecture By:- Mr. Akaash
  • 28.
    28 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Lecture By:- Mr. Akaash
  • 29.
    29 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Lecture By:- Mr. Akaash
  • 30.
    30 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Method Lecture By:- Mr. Akaash
  • 31.
    31 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Method Boolean value Lecture By:- Mr. Akaash
  • 32.
    32 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Method Boolean value Object Lecture By:- Mr. Akaash
  • 33.
    33 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Method Boolean value Object Method Lecture By:- Mr. Akaash
  • 34.
    34 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Method Boolean value Object Method Class Lecture By:- Mr. Akaash
  • 35.
    35 Coding of JFrame frame.setSize(280,150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } Object Method Width Height Object Method Keyword Method Object Method Boolean value Object Method Value Class Method Lecture By:- Mr. Akaash
  • 36.
    36 Explanation of PreviouslyUsed Methods setSize(). Method allows you to set the size like Width & height of JFrame setResizable(). One method for ensuring that a graphical interface looks the way you intend is to prevent the user from re-sizing it, using this method of JFrame : setLayout(). Method allows you to set the layout of the container, often a JPanel, to say FlowLayout(), BorderLayout(), GridLayout(), null layout(), or whatever layout desired. The layout manager helps lay out the components held by this container setDefaultCloseOperation() method is used to specify one of several options for the close button. Use one of the following constants to specify your choice:  JFrame.EXIT_ON_CLOSE — Exit the application.  JFrame.HIDE_ON_CLOSE — Hide the frame, but keep the application running.  JFrame.DISPOSE_ON_CLOSE — Dispose of the frame object, but keep the application running.  JFrame.DO_NOTHING_ON_CLOSE — Ignore the click. If you forget to call setDefaultCloseOperation() you will get JFrame.HIDE_ON_CLOSE by default. This can be frustrating, because it looks like you have "killed" the program, but it keeps on running, and you see no frame. Lecture By:- Mr. Akaash
  • 37.
    37 What is JTextArea? AJTextArea is a multi-line area that displays plain text. It is intended to be a lightweight component that provides source compatibility with the java.awt.TextArea class where it can reasonably do so. Lecture By:- Mr. Akaash
  • 38.
  • 39.
    39 Coding of JTextArea JTextAreatextArea1 = new JTextArea(text); textArea1.setPreferredSize(new Dimension(100, 100)); textArea1.setLineWrap(true); frame.add(textArea1); Class Object Keyword Constructor Value Object Method Keyword Method Width Height Object Method Boolean value Object Method Object Lecture By:- Mr. Akaash
  • 40.
    40 Constructors and Description JTextArea() Constructsa new TextArea. JTextArea(Document doc) Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0). JTextArea(Document doc, String text, int rows, int columns) Constructs a new JTextArea with the specified number of rows and columns, and the given model. JTextArea(int rows, int columns) Constructs a new empty TextArea with the specified number of rows and columns. JTextArea(String text) Constructs a new TextArea with the specified text displayed. JTextArea(String text, int rows, int columns) Constructs a new TextArea with the specified text and number of rows and columns. Lecture By:- Mr. Akaash
  • 41.
    41 Methods Modifier and TypeMethod and Description void append(String str) Appends the given text to the end of the document. protected Document createDefaultModel() Creates the default implementation of the model to be used at construction if one isn't explicitly given. AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this JTextArea. int getColumns() Returns the number of columns in the TextArea. protected int getColumnWidth() Gets column width. int getLineCount() Determines the number of lines contained in the area. int getLineEndOffset(int line) Determines the offset of the end of the given line. Lecture By:- Mr. Akaash
  • 42.
    42 Methods Modifier and TypeMethod and Description boolean getLineWrap() Gets the line-wrapping policy of the text area. Dimension getPreferredScrollableViewportSize() Returns the preferred size of the viewport if this component is embedded in a JScrollPane. Dimension getPreferredSize() Returns the preferred size of the TextArea. protected int getRowHeight() Defines the meaning of the height of a row. int getRows() Returns the number of rows in the TextArea. boolean getScrollableTracksViewportWidth() Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport. int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. Lecture By:- Mr. Akaash
  • 43.
    43 Methods Modifier & TypeMethod and Description Int getTabSize() Gets the number of characters used to expand tabs. String getUIClassID() Returns the class ID for the UI. Boolean getWrapStyleWord() Gets the style of wrapping used if the text area is wrapping lines. Void insert(String str, int pos) Inserts the specified text at the specified position. protected String paramString() Returns a string representation of this JTextArea. Void replaceRange(String str, int start, int end) Replaces text from the indicated start to end position with the new text specified. Void setColumns(int columns) Sets the number of columns for this TextArea. Void setTabSize(int size) Sets the number of characters to expand tabs to. Void setWrapStyleWord(boolean word) Sets the style of wrapping used if the text area is wrapping lines.
  • 44.
  • 45.
    45 Coding of JTextAreawith ScrollPane JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setLineWrap(true); JScrollPane scrollPane = new JScrollPane(textArea2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); frame.add(scrollPane); Lecture By:- Mr. Akaash
  • 46.
    46 Why JScrollPane usedwith JTextArea? A JTextArea object represents a multiline area for displaying text. If Text is too large from JTextArea Boundaries(Width, Height) then You can also put your JTextArea in a JScrollPane to make it scrollable. Lecture By:- Mr. Akaash
  • 47.

Editor's Notes

  • #12 What is Jframe? A frame, implemented as an instance of the JFrame class, is a window that has decorations such as a border, a title, and supports button components that close or iconify the window. Applications with a GUI usually include at least one frame.
  • #13 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #14 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #15 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #16 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #17 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #18 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #19 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #20 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #21 Coding of JFrame import java.awt.FlowLayout; import javax.swing.JFrame; public class JTextAreaTest { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea Test"); frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #22 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #23 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #24 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #25 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #26 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #27 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #28 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #29 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #30 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #31 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #32 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #33 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #34 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #35 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #36 Coding of JFrame frame.setSize(280, 150); frame.setLayout(new FlowLayout()); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
  • #38 What is JTextArea? A JTextArea is a multi-line area that displays plain text. It is intended to be a lightweight component that provides source compatibility with the java.awt.TextArea class where it can reasonably do so.
  • #40 Coding of JTextArea JTextArea textArea1 = new JTextArea(text); textArea1.setPreferredSize(new Dimension(100, 100)); textArea1.setLineWrap(true); frame.add(textArea1);
  • #41 Constructors and Description JTextArea() Constructs a new TextArea. JTextArea(Document doc) Constructs a new JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0). JTextArea(Document doc, String text, int rows, int columns) Constructs a new JTextArea with the specified number of rows and columns, and the given model. JTextArea(int rows, int columns) Constructs a new empty TextArea with the specified number of rows and columns. JTextArea(String text) Constructs a new TextArea with the specified text displayed. JTextArea(String text, int rows, int columns) Constructs a new TextArea with the specified text and number of rows and columns.
  • #42 Methods Modifier and Type Method and Description Void append(String str) Appends the given text to the end of the document. protected Document createDefaultModel() Creates the default implementation of the model to be used at construction if one isn't explicitly given. AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this JTextArea. Int getColumns() Returns the number of columns in the TextArea. protected int getColumnWidth() Gets column width. Int getLineCount() Determines the number of lines contained in the area. Int getLineEndOffset(int line) Determines the offset of the end of the given line.
  • #43 Methods Modifier and Type Method and Description Boolean getLineWrap() Gets the line-wrapping policy of the text area. Dimension getPreferredScrollableViewportSize() Returns the preferred size of the viewport if this component is embedded in a JScrollPane. Dimension getPreferredSize() Returns the preferred size of the TextArea. protected int getRowHeight() Defines the meaning of the height of a row. Int getRows() Returns the number of rows in the TextArea. Boolean getScrollableTracksViewportWidth() Returns true if a viewport should always force the width of this Scrollable to match the width of the viewport. Int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
  • #44 Methods Modifier and Type Method and Description Int getTabSize() Gets the number of characters used to expand tabs. String getUIClassID() Returns the class ID for the UI. Boolean getWrapStyleWord() Gets the style of wrapping used if the text area is wrapping lines. Void insert(String str, int pos) Inserts the specified text at the specified position. protected String paramString() Returns a string representation of this JTextArea. Void replaceRange(String str, int start, int end) Replaces text from the indicated start to end position with the new text specified. Void setColumns(int columns) Sets the number of columns for this TextArea. Void setTabSize(int size) Sets the number of characters to expand tabs to. Void setWrapStyleWord(boolean word) Sets the style of wrapping used if the text area is wrapping lines.
  • #46 Coding of JTextArea with ScrollPane JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setLineWrap(true); JScrollPane scrollPane = new JScrollPane(textArea2,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); frame.add(scrollPane);
  • #47 Why JScrollPane used with JTextArea? A JTextArea object represents a multiline area for displaying text. If Text is too large from JTextArea Boundaries(Width, Height) then You can also put your JTextArea in a JScrollPane to make it scrollable.