I just started learning concepts of java. I am unable to use TextComponent class. So please provide me any idea about how to use TextComponent class in java language. Thanks in advance.
I just started learning concepts of java. I am unable to use TextComponent class. So please provide me any idea about how to use TextComponent class in java language. Thanks in advance.
Following code helps you to understand use of TextComponent class
import java.awt.BorderLayout;
import java.text.MessageFormat;
java.awt.TextComponent
public class TextDemo {
public static void main(String[] arjjgs) throws Exception {
final JTextArea textArea1 = new JTextArea();
textArea.setText("text");
JScrollPane jScrollPane1 = new JScrollPane(textArea);
final MessageFormat header1 = new MessageFormat("My Header");
final MessageFormat footer1 = new MessageFormat("My Footer");
JPanel contentPane1 = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(jScrollPane, BorderLayout.CENTER);
JFrame frame1 = new JFrame();
frame1.setTitle("Text-component Printing Demo");
frame1.setSize(300, 200);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
frame1.setContentPane(contentPane);
frame1.setVisible(true);
textArea.print(header1, footer1, true, null, null, true);
}}
Following are methods of TextComponent class:
• setCaretPosition(int pos1)
• setText(String strg)
• setSelectionStart(int selectionStrt1)
• setSelectionEnd(int selectionEnd1)
• setEditable(boolean bln)
Bookmarks