package jTextarea;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.TextAttribute;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import javax.swing.*;
public class JScrollPane包裹JTextArea2405240055 extends JFrame{
public static void main(String[] args) {
try {
Class.forName(Thread.currentThread().getStackTrace()[1].getClassName()).getDeclaredConstructor().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
{
this.addWindowListener(new WindowAdapter() {
@Override public void windowClosing(WindowEvent ev) {
System.exit(0);
}
});
this.setTitle(getClass().getName());
this.setBounds(100, 100, 800, 600);
}
JScrollPane jScrollPane010;
JTextArea jTextArea010;
public JScrollPane包裹JTextArea2405240055() {
super();
jTextArea010 = new JTextArea(“”"
JScrollPane添加JTextArea可以在构造方法,也可以用 setViewportView( 方法
构造方法源码:
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
{
setLayout(new ScrollPaneLayout.UIResource());
setVerticalScrollBarPolicy(vsbPolicy);
setHorizontalScrollBarPolicy(hsbPolicy);
setViewport(createViewport());
setVerticalScrollBar(createVerticalScrollBar());
setHorizontalScrollBar(createHorizontalScrollBar());
if (view != null) {
setViewportView(view); // 就是调用 setViewportView( 方法
}
setUIProperty(“opaque”,true);
updateUI();
if (!this.getComponentOrientation().isLeftToRight()) {
viewport.setViewPosition(new Point(Integer.MAX_VALUE, 0));
}
}
“”");
HashMap<TextAttribute, Object> fontCfg = new HashMap<>();
fontCfg.put(TextAttribute.FAMILY, “宋体”);
fontCfg.put(TextAttribute.BACKGROUND, new Color(0x00f67799));
fontCfg.put(TextAttribute.FOREGROUND, Color.white);
fontCfg.put(TextAttribute.SIZE, 33); //字体大小尺寸
// fontCfg.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_ULTRABOLD); //最粗体
// fontCfg.put(TextAttribute.POSTURE, 0.2f); //斜体
Font font = Font.getFont(fontCfg);
jTextArea010.setFont(font);
jTextArea010.setBackground(Color.black);
// jScrollPane010 = new JScrollPane(jScrollPane010, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// jScrollPane010 = new JScrollPane(jScrollPane010, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane010 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// jScrollPane010 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane010.setViewportView(jTextArea010);
add(jScrollPane010);
this.setVisible(true);
}
}
package jTextarea;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.TextAttribute;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import javax.swing.*;
public class JScrollPane包裹JTextArea2405240055 extends JFrame{
/**
*
*/
private static final long serialVersionUID = -2238483862288329351L;
public static void main(String[] args) {
try {
Class.forName(Thread.currentThread().getStackTrace()[1].getClassName()).getDeclaredConstructor().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
{
this.addWindowListener(new WindowAdapter() {
@Override public void windowClosing(WindowEvent ev) {
System.exit(0);
}
});
this.setTitle(getClass().getName());
this.setBounds(100, 100, 800, 600);
}
JScrollPane jScrollPane010;
JTextArea jTextArea010;
public JScrollPane包裹JTextArea2405240055() {
super();
jTextArea010 = new JTextArea("""
JScrollPane添加JTextArea可以在构造方法,也可以用 setViewportView( 方法
构造方法源码:
public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
{
setLayout(new ScrollPaneLayout.UIResource());
setVerticalScrollBarPolicy(vsbPolicy);
setHorizontalScrollBarPolicy(hsbPolicy);
setViewport(createViewport());
setVerticalScrollBar(createVerticalScrollBar());
setHorizontalScrollBar(createHorizontalScrollBar());
if (view != null) {
setViewportView(view); // 就是调用 setViewportView( 方法
}
setUIProperty("opaque",true);
updateUI();
if (!this.getComponentOrientation().isLeftToRight()) {
viewport.setViewPosition(new Point(Integer.MAX_VALUE, 0));
}
}
""");
HashMap<TextAttribute, Object> fontCfg = new HashMap<>();
fontCfg.put(TextAttribute.FAMILY, "宋体");
fontCfg.put(TextAttribute.BACKGROUND, new Color(0x00f67799));
fontCfg.put(TextAttribute.FOREGROUND, Color.white);
fontCfg.put(TextAttribute.SIZE, 33); //字体大小尺寸
// fontCfg.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_ULTRABOLD); //最粗体
// fontCfg.put(TextAttribute.POSTURE, 0.2f); //斜体
Font font = Font.getFont(fontCfg);
jTextArea010.setFont(font);
jTextArea010.setBackground(Color.black);
// jScrollPane010 = new JScrollPane(jScrollPane010, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// jScrollPane010 = new JScrollPane(jScrollPane010, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane010 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// jScrollPane010 = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane010.setViewportView(jTextArea010);
add(jScrollPane010);
this.setVisible(true);
}
}