JScrollPane包裹JTextArea2405240055

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);
	}
	
	
	
	
	
	

}

  • 21
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kfepiza

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值