- 浏览: 86806 次
- 性别:
- 来自: 苏州
最新评论
-
Exynox:
没有看懂,
如何使用JTextArea
文章列表
//...where instance variables are declared:JPopupMenu popup;
//...where the GUI is constructed: //Create the popup menu. popup = new JPopupMenu(); menuItem = new JMenuItem("A popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMen ...
- 2009-10-26 10:16
- 浏览 786
- 评论(0)
1、Model
(1)DefaultListModel:你所需做的事情很少。
(2)AbstractListModel:你需要管理数据并发出事件。需要实现getSize和getElementAt方法。
(3) ListModel
2、初始化JList
list = new JList(data); //data has type Object[]list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);list.setLayoutOrientation(JList.HORIZONTAL_WRAP);list. ...
- 2009-10-26 10:13
- 浏览 3108
- 评论(0)
该类容器提供了第三维度上的坐标,即Depth(或Z order),该值越大越显示在上方。
处于同一Depth的组件,可以通过设置Postion表示相互之间的关系。
- 2009-10-26 09:49
- 浏览 1145
- 评论(0)
可以在JLabel中使用HTML,以增加多种显示效果。
JLabel在默认情况下是透明的,如果想显示JLabel的背景色,请显示调用setOpaque。
一般情况下,JLabel是用来描述另外一个组件,这种情况下可以调用setLabelFor,增加用户的体验。
调用void setHorizontalAlignment(int)、void setVerticalAlignment(int)设置标签内部内容的对齐方式;
调用setHorizontalTextPosition(int) 、void setVerticalTextPosition(int)设置标签 ...
- 2009-10-26 09:41
- 浏览 963
- 评论(0)
为了创建MDI风格的GUI,可以选择JInternalFrame,并将其放入JDesktopPane中。
...//In the constructor of InternalFrameDemo, a JFrame subclass:
desktop = new JDesktopPane();
createFrame(); //Create first window
setContentPane(desktop);
...
//Make dragging a little faster but perhaps uglier.
...
- 2009-10-24 20:19
- 浏览 4194
- 评论(0)
JFormattedTextField在JTextField基础上增加了formatter和一个value对象。formatter可以将value转换成显示的文本,或把文本转换成value。
1、创建和初始化
rateField = new JFormattedTextField(percentFormat);
rateField.setValue(new Double(rate));
rateField.setColumns(10);
rateField.addPropertyChangeListener("value& ...
- 2009-10-24 19:50
- 浏览 2607
- 评论(0)
JFileChooser用来提供一个文件对话框,可以通过其showXxxDialog打开一个模态对话框,或直接实例化并加入到其他组件。
1、直接通过API打开对话框
//Create a file chooser
final JFileChooser fc = new JFileChooser();
. ..
//打 ...
- 2009-10-22 19:54
- 浏览 5144
- 评论(0)
JEditoPane和JTextPane均是带格式的文本组件,其中JTextPane是JEditorPane的子类。
1、使用EditorPane显示HTML文件
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
java.net.URL helpURL = TextSamplerDemo.class.getResource(
"TextSamplerDemoHelp.html&quo ...
- 2009-10-22 19:19
- 浏览 2138
- 评论(0)
1、对话框的特性
对话总是依赖父窗口(JFrame),当父窗口关闭,对话框也被关闭,父窗口最小化,对话框随之最小化。对话框分模态和非模态两类。
2、使用JOptionPane创建对话框
通过该类的showXxxDialog方法,如果是在JInternalFrame中使用,用相应的showInternalXxxDialog方法,通过这些方法创建的对话框都是模态的。如果想创建非模态的,可以直接实例化JOptionPane,注册PropertyChangeListener,并将其添加到JDialog中去。
- 2009-10-22 18:57
- 浏览 804
- 评论(0)
Swing中由JComboBox表示一个组合框。组合框表面上看来像下拉列表、文本框和一个下拉按钮的组合,分可编辑和不可编辑两类。
有多种组件允许用户进行选择,如单选按钮,复选按钮,列表(JList)等,当界面空间有限并且项目不定(可能需要输入)请用JComboBox,但如果项目很多,请使用JList。
1、使用不可编辑的JComboBox
String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };
//C ...
- 2009-10-22 14:40
- 浏览 10029
- 评论(0)
使用JColorChooser可以为自己的JAVA应用提供一个颜色选择器。JColorChooser本身就是一个组件,可以添加到任何容器中去。另外,JColorChooser提供一些API使用对话框形式进行颜色选择。
颜色选择器由两部分组成:ChooserPanel、Pr ...
- 2009-10-20 20:19
- 浏览 965
- 评论(0)
setAction setTex setIcon setDisabledIcon setPressedIcon setSelectedIcon setRolloverIcon
setHorizontalAlignment setVerticalAlignment setHorizentalTextPosition setVerticalTextPostion setMargin setFocusPainted setBorderPainted setIconTextGap
setMnemonic setDisplayedMnimonicIndex setActionCommand add ...
- 2009-10-20 20:09
- 浏览 770
- 评论(0)
设置属性:setEditbale setDragEnabled setDisabledTextColor setMargin
选择:getSelectedText selectAll select getSelectionStart getSelectionEnd setSelectionColor setSelectedTextColor
模型和视图坐标变换:modelToView viewToModel
编辑命令: cut copy paste replaceSelection getActions getInputMap
操作光标和选择亮区:setCaret setCaretC ...
- 2009-10-20 19:53
- 浏览 777
- 评论(0)
一、概述
JTextComponent是Swing中所有文本组件的超类。它具有以下几个特性:
1、模型,即Document,管理组件内容;
2、视图
3、控制器,即Editor kit,读或写文本,并提供一些文本编辑的action
4、支持有限的撤销和重复操作
5、光标,光标过滤器和光标导航。
二、关联text action和菜单或按钮
menu.add(getActionByName(DefaultEditorKit.cutAction) //通过文本组件的getActions方法可以获得该组件支持的全部action,并将 ...
- 2009-10-20 17:02
- 浏览 818
- 评论(0)
组件外观:setBorder setBackgroud setForeground setFont setCursor setOpaque
组件状态:setComponentPopupMenu setTransferHandler setTooltipText isShowing setVisible setEnable
事件处理:addHierarchyListener addMouseListener addMouseMotionListener addKeyListener addComponentListener contains getComponentAt
绘制组件:repa ...
- 2009-10-20 10:30
- 浏览 1114
- 评论(0)