텍스트 컨트롤을 사용하여 자식 대화 상자를 생성하는 Java Swing 응용 프로그램이 있습니다. 그리고 문제는 자식 대화 상자에서 자판 배열을 변경할 때 대화 상자가 닫힌 직후 다시 바뀝니다.스윙 앱에서 자판 배열을 유지 하시겠습니까?
내가 필요로하는 것은 메인 프레임이나 하위 프레임에서 전환되었는지 여부를 전환 한 후에 머무르는 키 보드 레이아웃입니다.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class InheritInputContext {
public static void main(String[] arg) {
final MainFrame mainFrame = new MainFrame();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
mainFrame.setPreferredSize(new Dimension(300, 400));
mainFrame.pack();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
});
}
}
class MainFrame extends JFrame {
MainFrame() {
setLayout(new BorderLayout());
JTextArea textArea = new JTextArea();
add(textArea, BorderLayout.CENTER);
JButton dialogBtn = new JButton("Dialog");
add(dialogBtn, BorderLayout.SOUTH);
dialogBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ChildDialog cd = new ChildDialog(MainFrame.this);
cd.setPreferredSize(new Dimension(200, 200));
cd.setLocationRelativeTo(MainFrame.this);
cd.pack();
cd.setVisible(true);
}
});
}
}
class ChildDialog extends JDialog {
ChildDialog(Window w) {
super(w);
JTextArea textArea = new JTextArea();
getContentPane().add(textArea);
}
}
운영체제의 키보드 레이아웃에 대해 이야기하고 있습니까? 조금 혼란스러워. –