Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

Swingطريقة تغيير نوع و لون و حجم خط الـ JTextArea

المثال التالي يعلمك طريقة تغيير نوع و حجم و لون الخط لكائن الـ JTextArea.


مثال

Main.java
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import java.awt.Font;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس
JTextArea textArea = new JTextArea(); // textArea إسمه JtextArea هنا قمنا بإنشاء
Font newFont = new Font("Arial", Font.BOLD, 16); // حجمه 16 Arial يمثل نوع خط عريض إسمه Font هنا أنشأنا كائن من الكلاس
textArea.setBounds(40, 40, 200, 100); // frame في الـ Text Area هنا قمنا بتحديد حجم و موقع الـ
textArea.setFont(newFont); // newFont يستخدم الـ textArea هنا جعلنا الـ
textArea.setForeground(Color.blue); // أزرق textArea هنا جعلنا لون خط الـ
textArea.setText("Blue\nText\nArea"); // textArea هنا قمنا بإدخال نص بداخل الـ
frame.add(textArea); // frame في الـ textArea هنا أضفنا الـ
frame.setSize(300, 250); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج
frame.setLayout(null); // الذي قمنا بإضافته سابقاً Text Area لذلك قمنا بتحديد مكان الـ Layout Manager أي لم نستخدم أي null هنا وضعنا
frame.setVisible(true); // هنا جعلنا النافذة مرئية
}
}
import java.awt.Color; import javax.swing.JFrame; import javax.swing.JTextArea; import java.awt.Font; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("JTextArea demo"); // أي قمنا بإنشاء نافذة مع وضع عنوان لها JFrame هنا أنشأنا كائن من الكلاس JTextArea textArea = new JTextArea(); // textArea إسمه JtextArea هنا قمنا بإنشاء Font newFont = new Font("Arial", Font.BOLD, 16); // حجمه 16 Arial يمثل نوع خط عريض إسمه Font هنا أنشأنا كائن من الكلاس textArea.setBounds(40, 40, 200, 100); // frame في الـ Text Area هنا قمنا بتحديد حجم و موقع الـ textArea.setFont(newFont); // newFont يستخدم الـ textArea هنا جعلنا الـ textArea.setForeground(Color.blue); // أزرق textArea هنا جعلنا لون خط الـ textArea.setText("Blue\nText\nArea"); // textArea هنا قمنا بإدخال نص بداخل الـ frame.add(textArea); // frame في الـ textArea هنا أضفنا الـ frame.setSize(300, 250); // هنا قمنا بتحديد حجم النافذة. عرضها 300 و طولها 250 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // هنا جعلنا زر الخروج من النافذة يغلق البرنامج frame.setLayout(null); // الذي قمنا بإضافته سابقاً Text Area لذلك قمنا بتحديد مكان الـ Layout Manager أي لم نستخدم أي null هنا وضعنا frame.setVisible(true); // هنا جعلنا النافذة مرئية } }

ستظهر لك النافذة التالية عند التشغيل.

تغيير لون و حجم و نوع خط ال JtextArea في جافا

الدورات

أدوات مساعدة

أقسام الموقع

دورات
مقالات كتب مشاريع أسئلة