逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::
    private static void createAndShowGUI() {
        JFrame frame 
= new JFrame("Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(
350400);

        
try {
            JTextPane textPane 
= new JTextPane();
            StyledDocument doc 
= (StyledDocument) textPane.getDocument();
            Style style 
= doc.addStyle("StyleName"null);

            
// Italic
            StyleConstants.setItalic(style, false);

            
// Bold
            StyleConstants.setBold(style, true);
            doc.insertString(doc.getLength(), 
"Some Text\n", style);

            
// Font Family
            StyleConstants.setFontFamily(style, "tahoma");

            
// Font Size
            StyleConstants.setFontSize(style, 30);
            doc.insertString(doc.getLength(), 
"Some Text\n", style);

            
// Background Color
            StyleConstants.setBackground(style, Color.blue);
            
            
// Insert an image icon
            StyleConstants.setIcon(style, new ImageIcon("Adium.png"));

            
// Foreground Color
            StyleConstants.setForeground(style, Color.white);

            
// Append to document.
            doc.insertString(doc.getLength(), "Some Text", style);
            
            frame.getContentPane().add(textPane);
        } 
catch (BadLocationException e) {
        }

        frame.setVisible(
true);
    }


单行输入用JTextField
多行输入用JTextArea
密码输入用JPasswordField
简单网页载入用JEditorPanel, 添加hyperlinklistener
格式化的用JTextPane
控制只能输入数字等可以JFormattedTextField
NumberFormat
解析日期可用SimpleDateFormat

posted on 2008-03-17 07:48 逛奔的蜗牛 阅读(343) 评论(0)  编辑 收藏 引用 所属分类: Java

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理