JOptionPane JComponent 의 하위 클래스입니다. 정적 메서드를 포함하는 클래스 모달 생성 및 사용자 정의 대화 상자 . JOptionPane JDialog 대신 클래스를 사용할 수 있습니다. 클래스 코드의 복잡성을 최소화합니다. JOptionPane은 네 가지 표준 아이콘(질문, 정보, 경고, 및 오류 ) 또는 사용자가 지정한 사용자 정의 아이콘. 기본적으로 JOptionPane 메시지 대화 상자는 한 줄 텍스트를 지원할 수 있습니다. 긴 텍스트로 JOptionPane 메시지 대화 상자를 구현할 수도 있습니다. t JTextArea를 사용자 정의하여 수업.
예시
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JOptionPaneScrollTextMessage extends JFrame {
private JButton btn;
String msg;
public JOptionPaneScrollTextMessage() {
setTitle("JOptionPaneScrollTextMessage Test");
msg = " Java is a programming language that produces software for multiple platforms.\n When a programmer writes a Java application, the compiled code\n" + "(known as bytecode) runs on most operating systems (OS), including \n Windows, Linux and Mac OS. Java derives much of its syntax \n from the C and C++" + "programming languages.\n Java was developed in the mid-1990s by James A. Gosling, a former computer scientist with Sun Microsystems.";
btn = new JButton("Show Dialog");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JTextArea jta = new JTextArea(5, 15);
jta.setText(msg);
jta.setEditable(false);
JScrollPane jsp = new JScrollPane(jta);
JOptionPane.showMessageDialog(null, jsp);
}
});
add(btn, BorderLayout.NORTH);
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
new JOptionPaneScrollTextMessage();
}
} 출력
