java图形界面中的图片显示_第1页
java图形界面中的图片显示_第2页
java图形界面中的图片显示_第3页
java图形界面中的图片显示_第4页
java图形界面中的图片显示_第5页
已阅读5页,还剩2页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、java图形界面中的图片显示不好 2011-06-13 12:44 1203670773 | 分类:JAVA相关 | 浏览342次我在Java的JDialog中想添加一个图片想填充整个对话框,添加后的图片却显示不出来,然后在用鼠标东一下对话框,图片就显示出来了。怎么回事呀精彩回答2011-06-20 02:59package hao;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.GridLayout;import java.io.File;import j

2、avax.swing.BorderFactory;import javax.swing.Box;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextPane;import javax.swing.text.Ba

3、dLocationException;import javax.swing.text.SimpleAttributeSet;import javax.swing.text.StyleConstants;import javax.swing.text.StyledDocument;public class ChatPanel extends JPanel private static final long serialVersionUID = 1L; JButton send,record,saveRecord,image; JTextArea inputArea; JTextPane text

4、;/注意用法* JComboBox fontName = null, fontSize = null, fontStyle = null, fontColor = null,fontBackColor = null; public StyledDocument doc = null; JScrollPane scrollPane;JPanel textChat; JButton music; public ChatPanel() setLayout(new BorderLayout(); text = new JTextPane(); text.setEditable(false); doc

5、= text.getStyledDocument();/跟踪文本和图片写到该区域的位置* scrollPane = new JScrollPane(text); /注意下面对JComboBox的巧用* String str_name = ; String str_Size = ; String str_Style = ; String str_Color = ; String str_BackColor = ; fontName = new JComboBox(str_name); fontSize = new JComboBox(str_Size); fontStyle = new JCom

6、boBox(str_Style); fontColor = new JComboBox(str_Color); fontBackColor = new JComboBox(str_BackColor); fontName.setBackground(new Color(255,153,255); fontSize.setBackground(new Color(255,153,255); fontStyle.setBackground(new Color(255,153,255); fontColor.setBackground(new Color(255,153,255); fontBack

7、Color.setBackground(new Color(255,153,255); Box box = Box.createVerticalBox();/创建一个可以容纳多个Box组件的Box* Box box_1 = Box.createHorizontalBox(); Box box_2 = Box.createHorizontalBox(); Box box_4 = Box.createHorizontalBox(); box.add(box_1); box.add(box_2); box.add(box_4); JLabel b1= new JLabel("字体"

8、;), b2 = new JLabel("样式"),b3 = new JLabel("字号"),b4 = new JLabel("颜色"),b5 = new JLabel("背景"); b1.setBackground(new Color(255,153,255); b2.setBackground(new Color(255,153,255); b3.setBackground(new Color(255,153,255); b4.setBackground(new Color(255,153,255); b5.

9、setBackground(new Color(255,153,255); box_1.add(b1); box_1.add(fontName); box_1.add(Box.createHorizontalStrut(8); box_1.add(b2); box_1.add(fontStyle); box_1.add(Box.createHorizontalStrut(8); box_1.add(b3); box_1.add(fontSize); box_2.add(Box.createHorizontalStrut(8); box_2.add(b4); box_2.add(fontColo

10、r); box_2.add(Box.createHorizontalStrut(8); box_4.add(b5); box_4.add(fontBackColor);textChat = new JPanel(); textChat.setLayout(new BorderLayout(); textChat.setBackground(new Color(255,153,255); inputArea = new JTextArea(3, 20); inputArea.setLineWrap(true); /设置文本区的换行策略。88888*send = new JButton("

11、;发送"); record=new JButton("显示记录"); saveRecord=new JButton("储存记录"); image=new JButton("表情"); send.setBackground(new Color(255,153,255); record.setBackground(new Color(255,153,255); saveRecord.setBackground(new Color(255,153,255); image.setBackground(new Color(255,15

12、3,255); Box box_3 = Box.createHorizontalBox(); box_3.add(send); box_3.add(Box.createHorizontalStrut(8);/设置按钮间距*888 box_3.add(record); box_3.add(Box.createHorizontalStrut(8); /设置按钮间距*888 box_3.add(saveRecord); box_3.add(Box.createHorizontalStrut(8);/设置按钮间距*888 box_3.add(image); box.setBorder(BorderFa

13、ctory.createLineBorder(new Color(102,102,0),5);/设置Box的边框线* box_3.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),5); textChat.add(box,BorderLayout.NORTH); textChat.add(inputArea,BorderLayout.CENTER); textChat.add(box_3, BorderLayout.SOUTH); inputArea.requestFocus(true); inputArea.setBo

14、rder(BorderFactory.createLineBorder(new Color(102,102,0),5);/设置输入窗口边框线* text.setBorder(BorderFactory.createLineBorder(new Color(102,102,0),8);/设置输入窗口边框线* JPanel audioPanel = new JPanel();/最上面的边框* audioPanel.setBackground(new Color(255,153,255); audioPanel.setLayout(new GridLayout(1,1); music = new J

15、Button("想听就听"); music.setPreferredSize(new Dimension(320,50); music.setBorder(BorderFactory.createLineBorder(Color.BLACK,10);/设置输入窗口边框线* audioPanel.add(music);add(audioPanel, BorderLayout.NORTH); add(scrollPane,BorderLayout.CENTER); add(textChat, BorderLayout.SOUTH); void insertIcon(ImageI

16、con image) text.setCaretPosition(doc.getLength(); text.insertIcon(image); insert(new MessageStyle();/?/ public void insert(MessageStyle attrib) try doc.insertString(doc.getLength(), attrib.getText() + "n", attrib.getAttrSet();/写完后接着换行* catch (BadLocationException e) e.printStackTrace(); pu

17、blic MessageStyle getMessageStyle(String line) MessageStyle att = new MessageStyle(); att.setText(line); att.setName(String) fontName.getSelectedItem(); att.setSize(Integer.parseInt(String) fontSize.getSelectedItem(); String temp_style = (String) fontStyle.getSelectedItem(); if (temp_style.equals(&q

18、uot;常规") att.setStyle(MessageStyle.GENERAL); else if (temp_style.equals("粗体") att.setStyle(MessageStyle.BOLD); else if (temp_style.equals("斜体") att.setStyle(MessageStyle.ITALIC); else if (temp_style.equals("粗斜体") att.setStyle(MessageStyle.BOLD_ITALIC); String temp_

19、color = (String) fontColor.getSelectedItem(); if (temp_color.equals("黑色") att.setColor(new Color(0, 0, 0); else if (temp_color.equals("红色") att.setColor(new Color(255, 0, 0); else if (temp_color.equals("蓝色") att.setColor(new Color(0, 0, 255); else if (temp_color.equals("黄色") att.setColor(new Color(255, 255, 0); else

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论