java的文本域
發布時間: 2023-07-14 07:49:24
① java 如何設置文本域顯示的默認字
JTextArea有一個public JTextArea(String text, int rows, int columns)的構造函數,text就可以表示默認文字,rows表示行數,colums表示列數。也可以在顯示之前調用public void setText(String t)方法設置。例如像下面這樣:
publicclassWinTest7
{
publicstaticvoidmain(String[]args)
{
JFrameframe=newJFrame();
JTextAreaarea=newJTextArea("welcomtotextarea!",40,50);
area.setText("thisisnewdefaultString");
frame.add(area);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setLayout(newFlowLayout());
frame.setVisible(true);
}
}
熱點內容