java 使用TextField定義普通文本框


 1 package test;
2
3 import java.awt.Container;
4 import java.awt.Font;
5 import java.awt.GridLayout;
6 import java.io.File;
7 import java.util.EmptyStackException;
8 import java.util.Iterator;
9 import java.util.Stack;
10
11 import javax.swing.Icon;
12 import javax.swing.ImageIcon;
13 import javax.swing.JButton;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JScrollPane;
18 import javax.swing.JSpinner;
19 import javax.swing.JSplitPane;
20 import javax.swing.JTabbedPane;
21 import javax.swing.JTextField;
22 import javax.swing.JToggleButton;
23
24 public class ImplementsDemo {
25 public static void main(String[] args) throws EmptyStackException{
26 JFrame f=new JFrame("Welcome To Earth!");
27 JTextField name=new JTextField(30);
28 JTextField noed=new JTextField("HJW",10);
29 JLabel nameLab=new JLabel("輸入用戶姓名:");
30 JLabel noedLab=new JLabel("不可編輯文本 ");
31 noed.setEnabled(false);
32 name.setColumns(30);
33 noed.setColumns(30);
34 f.setLayout(new GridLayout(2,2));//設置布局管理器
35 f.add(nameLab);
36 f.add(name);
37 f.add(noedLab);
38 f.add(noed);
39 f.setSize(300,100);
40 f.setLocation(300,200);
41 f.setVisible(true);
42
43 }
44
45 }


如果取消掉布局管理器,才會使setColumns()為有效語句。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM