一、如何给JTextArea添加滚动条
话不多说,代码见
//创建滚动条
JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setBounds(28, 209, 752, 265);
//全局加入滚动条
contentPane.add(scrollPane_1);
//创建JTextArea
JTextArea textArea = new JTextArea();
textArea.setBounds(28, 209, 752, 265);
//滚动条添加JTextArea
scrollPane_1.setViewportView(textArea);
//全局加入滚动条JTextArea
contentPane.add(textArea);
二、实现弹窗的方式
使用JOptionPane类中的方法showMessageDialog()即可实现,该方法具体内容如下:
public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException
相关参数的定义如下:
parentComponent - 确定弹窗的父Frame; 如果传入参数为null 或 parentComponent 本身不带有 Frame,则使用默认的Frame。
message - 弹窗显示的内容
title - 弹窗的标题
messageType - 弹窗类型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、 QUESTION_MESSAGE 或 PLAIN_MESSAGE
如:
JOptionPane.showMessageDialog(null,"添加成功");