Understanding Swing’s Model

 

Understanding Swing’s Model

 

经常用Swing 开发Java GUI 程序的人一定听过这样的说法,Swing 控件是按MVC结构设计的。更准确地说,SwingModel-driven的结构。但不同Swing控件的Model,其作用是否相同呢?比如当你在使用JButton时,你很少需要关心ButtonModel的存在,但在JTable使用时,你却总是需要用到 TableModel。更进一步,当你频繁的使用JTable,你会发现你可能不仅用到了TableModel,还用到TableColumnModel, ListSelectionModel。这使我们意识到,Model存在不同的种类,不同类型的Model实现不同的功能。

 

GUI-State Model

 

首先,我们讨论第一种Model GUI–State ModelGUI-State Model的作用在于标识控件的视觉状态 (visual status)。例如按钮是否被点击,列表中的Item是否被选中。Swing的控件会代理对GUI-State Model的操作,通常我们不要直接操作GUI–State Model

 

ButtonModel

 

最常见的GUI-State ModelButtonModel,属于这个范畴的控件有JButton JToggleButton JCheckBox JRadioButton JMenu JMenuItem JCheckBoxMenuItem JRadioButtonMenuItem(所有AbstractButton的子类)

ButtonModel需要标识的状态有:

  1. PRESSED: Button是否被点击了
  2. ENABLED: Button能否被点击(是否显示呈灰色)
  3. ROLLOVER: 鼠标是否从Button上划过。Button通过判断这个属性判断是否要显示RolloverIcon,当然前提是Button通过setRolloverIcon,设置了RolloverIcon
  4. SELECTED: 只对RadioButton or Checkbox 有用
  5. ARMED: 鼠标点击Button后,是否在Button该释放

显而易见,这些属性都只和显示有关。对于GUI-State Model,只有以下两种情况我们需要关心它的处在 :(1)我们想改变控件缺省的视觉行为(假定这种情况很少发生) (2)出于某种显示目的共用Model,操作一个控件会改变另外一个控件的状态(下面会讨论到这种情况),其他情况下我们可以忽视它。当然还有一种情况我们需要注意,这就是在使用JRadioButton时。因为使用JRadioButton时,一组JRadioButton同时只能有一个被选中(SELECTED),这当然只有通过操作ButtonModelSELECTED属性来实现。不过,Swing针对这个问题引入了ButtonGroup类,通过ButtonGroup.add()方法设置同一个 button group,因此我们同样不需要直接操作ButtonModel

 

BoundedRangeModel

 

另一个常见的GUI-State ModelBoundedRangeModel,属于这个范畴的控件有JProgressBar  JScrollBar JSlider

BoundedRangeModel标识的主要状态有:min,max,value(int),同样的,我们很少直接操作BoundedRangeModel。使用JProgressBar 最常见的方式是在构造函数里指定min,max或是通过get/set读写min,max,value。而控件再把这些请求转发给BoundedRangeModel

前面提到出于某种显示目的,我们有可能需要直接操作GUI-State Model。以下是一种可能的情况(scenario):当我们把一幅面积较大的图像放在JScrollPane,同时希望通过移动滑杆(JSlider)来控制显示图像显示在JScrollPane的部分。常见的做法是监听BoundedRangeModelChangeEvent事件(addChangeListener(ChangeListener l)),JSlider改变了Model的值时在ChangeListener对显示作相应的调整。

 

TableColumnModel

 

TableColumnModelJTable特有的GUI-State ModelTableColumnModel用于管理TableColumn。而TableColumn代表了JTable中的每一列数据的视觉属性,比如该列对应的data-model index(这决定了要显示的内容,参见后面叙述),该列的宽度是否可变,列的最大、最小、首选宽度;该列的绘制器TableCellRenderer和编辑器TableCellEditor(JTable是面向列的,它基于每一列进行绘制和编辑)

 

Selection Model

 

考虑这样一个问题,当使用JTable时,如何设定从X行到Y行处于选择状态呢?

我们可以通过调要JTable.setRowSelectionInterval(int index0, int index1)来实现。再进一步,如果想实现反转选择(Toggle Selection),即单击齐数次处于选择状态,偶数次则处于非选择状态,JTable没有提供直接的方法来实现。因为JTable将选择的工作交由Selection Model来实现。察看setRowSelectionInterval的实现

public void setRowSelectionInterval(int index0, int index1) {

selectionModel.setSelectionInterval(boundRow(index0), boundRow(index1));

    }

要实现Toggle Selection就只有直接对Selection Model进行编程。

Selection Model也属于GUI- State Model的范畴,因为它标识也是一种视觉的状态,选中的Item会加亮(high light)。和其他GUI- State Model一样,通常我们不需要直接操作Selection Model

Selection Model标识的状态有:

  1. SINGLE_SELECTION
  2. SINGLE_INTERVAL_SELECTION
  3. MULTIPLE_INTERVAL_SELECTION

 

我们分析一下其他需要判断用户选择几种控件

  1. JList, 和 JTable一样用的是ListSelectionModel
  2. JTree, JTree需要的Selection Model最复杂,因此它有专门Selection Model: TreeSelectionModel
  3. JComboBox只能是单选,因此不需要有专门Selection Model
  4. JFileChooser,通过设置 FILES_ONLY DIRECTORIES_ONLY FILES_AND_DIRECTORIES (int) 来设定用户是否可选择文件,目录,或两者都可以。通过设定multiSelectionEnabled属性来决定是否单选或多选,通过File数组 selectedFiles记录当前的选择
  5. JTabbedPane, JTabbedPane的情况有些特殊,虽然JTabbedPane也只能单选,但它能有专门的Selection Model: SingleSelectionModel

对待Selection Model的方式和其他GUI-State Model一样,相应Jcomponent都提供专门的函数屏蔽我们对它的直接操作。

 

Application-data model

 

这类的Model决定了显示在控件中的内容,因此往往需要我们直接的操作。他们分别是:

  1. JList: ListModel
  2. JTable: TableModel
  3. JComboBox: ComboBoxModel
  4. JTree: TreeModel
  5. 各类Text控件:Document

 

ListModel

 

Swing首先定义了接口ListModel

然后定义了抽象类AbstractListModel实现这个接口。在抽象类里没有定义实际数据的存储方式。因此要实现AbstractListModel,用户还需要定义这两个函数

  1. public int getSize();
  2. public Object getElementAt(int index);

因为没有定义实际数据的存储方式,当然没有办法提供这两个函数的实现。

最后Swing提供缺省类DefaultListModel实现抽象类,缺省类以Vector作为存储数据的方式。

构造一个JList的实例有四种方式:

JList()          

JList(final Object[] listData)

JList(final Vector listData)

JList(ListModel dataModel)

前三种构造函数里会分别生成相应的ListModel。还可以在构造完后JList还可以用以下的函数来制定ListModel

void setListData(final Object[] listData)          

void setListData(final Vector listData)          

void setModel(ListModel model)

 

JList没有提供编辑其Item的方法,用户是无法直接编辑其Item的(这点和JComboBox不同,JComboBox提供了直接编辑其Item的方法),要改变Item的内容需要直接操作ListModel(用数组和Vector生成JList不适合用来显示可变内容的数据)。

要显示可变内容的JList,最方便的方法是用DefaultListModel,但由于它用Vcetor作为其内部的存储数据的方式,决定他们在处理大数据量的显示时是不适宜的。首先Vector有内部容量的概念,当容量不足以容纳更多的数据时,它需要重新分配一块内存,复制原内存的东西,并把原来的内存丢弃,这是非常耗时的动作;其次,Vector是线程安全的容器(thread-safe collection),所有对容器的操作都需要同步(synchronized),对于包含大数据量的collection这也是非常耗时的。

因此对于大数据量的Application-data,用户如果想用collection,应该在ArrayListLinkedList(thread-unsafe collection)之间选择:

  1. ArrayList也有内部容量的概念,但它提供了随机存取的功能 (random access), 使用它时可以预先申请一块较大的内存,以免以后重新分配内存。
  2. LinkedList没有内部容量的概念,因此不会重新分配内存,但它不提供随机存取的功能。

 

TableModel

 

SwingTableModel的处理和ListModel类似:

首先定义了接口TableModel

然后定义了抽象类实现这个接口AbstractTableModel。在抽象类里没有定义实际数据的存储方式。

要实现AbstractTableModel,用户还需要定义这三个函数

  1. public getColumnCount()
  2. public Object getValueAt(int rowIndex, int columnIndex)
  3. public int getRowCount()

public String getColumnName(int column) 往往也需要定义,不然在表头将显示为A,B,C,D …

最后Swing提供缺省类DefaultTableModel实现抽象类,缺省类以Vector作为存储数据的方式。因此对大数据量的操作(比如用JTable显示数据库查询的结果)同样不适合用DefaultTableModel。当用JTable显示数据库查询的结果,最好是扩展

AbstractTableModel,并让数据库每次只返回批量的数据。

 

JTable的构造函数比起JList要复杂一些, 因为它还需要指定TableColumnModel。但对于Application-data model 的处理和JList是一样的。

 

ComboBoxModel

 

JComboBoxJList很相似,都是用来显示一个列表项,并可以接受用户的选择 (JRadioButton也实现这个功能)。但他们也有本质的不同,JComboBox可以接受用户的输入,并可以编辑已有的选项。通常在使用JComboBox是把它分成两类:可编辑的和不可编辑的。缺省状态是不可编辑的,通过调用JComboBox.setEditable(true)可将JComboBox设置成可编辑。对应这两种状态JComboBox定义了两类data-model接口,ComboBoxModelMutableComboBoxModel

 

ComboBoxModel的定义如下:

public interface ComboBoxModel extends ListModel {

  void setSelectedItem(Object anItem);

  Object getSelectedItem();

}

它扩展ListModel并只是定义了用于获取和设置当前选项的办法,这是因为JComboBox没有Selection Model

MutableComboBoxModel,顾名思义,当然是定义修改data-model的方法,它的定义如下:

public interface MutableComboBoxModel extends ComboBoxModel {

    public void addElement( Object obj );

    public void removeElement( Object obj );

    public void insertElementAt( Object obj, int index );

    public void removeElementAt( int index );

}

Swing提供对MutableComboBoxModel的实现DefaultComboBoxModel,其内部Vector来存储数据,当我们想提供自己的现实时,最方便的方法是可以扩展AbstractListModel, 并选择是实现ComboBoxModel还是MutableComboBoxModel

 

构造一个JComboBox实例有四种方法:

public JComboBox()

public JComboBox(final Object items[])

public JComboBox(Vector items)

public JComboBox(ComboBoxModel aModel)

前三种构造函数里会分别生成相应的DefaultComboBoxModel(个人觉得这样构造JComboBox并不好,由于没有通过构造函数建立不变性 (invariants) ,即该JComboBox是否可编辑的,当需要修改data-model时,JComboBox都需要首先判断data-model是否可编辑,对于不可编辑的JComboBox调用编辑函数会丢出RuntimeException ())

 

TreeModel

 

TreeModel时最复杂的一种data-model,参考文献一有详细说明

 

 

各类Text控件

 

各类Text控件是比较独立的主题,这里不再详述。

参考文献

[1] Understanding the TreeModel

http://java.sun.com/products/jfc/tsc/articles/jtree/

[2] A Swing Architecture Overview http://java.sun.com/products/jfc/tsc/articles/architecture/index.html

[3] JGuru Faq:

http://www.jguru.com/faq/

[4] « Swing » by Matthew Robinson & Pavel Vorobiev

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

很经典的java swing书籍,高清版。找了好久找到的。 Part I Foundations 1 1 Swing overview 3 1.1 AWT 3 1.2 Swing 4 Z-order 5, Platform independence 5, Swing package overview 5 1.3 MVC architecture 7 Model 7, View 8, Controller 8, Custom view and controller 8, Custom models 9 1.4 UI delegates and PLAF 11 The ComponentUI class 11, Pluggable look and feel 12, Where are the UI delegates? 13 2 Swing mechanics 15 2.1 JComponent properties, sizing, and positioning 15 Properties 15, Size and positioning 18 2.2 Event handling and dispatching 19 EventListenerList 22, Event-dispatching thread 22 2.3 Multithreading 23 Special cases 26, How do we build our own thread-safe methods 26, 2.4 Timers 27 2.5 AppContext services 28 xii CONTENTS 2.6 Inside Timers and the TimerQueue 30 2.7 JavaBeans architecture 31 The JavaBeans component model 31, Introspection 31, Properties 32, Customization 32, Communication 32, Persistency 32, A simple Swing-based JavaBean 33 2.8 Fonts, colors, graphics, and text 38 Fonts 38, Colors 40, Graphics and text 40 2.9 Using the Graphics clipping area 47 2.10 Graphics debugging 49 Graphics debugging options 50, Graphics debugging caveats 51, Using graphics debugging 51 2.11 Painting and validation 54 Double buffering 55, Optimized drawing 55, Root validation 56, RepaintManager 57, Revalidation 57, Repainting 58, Painting 59, Custom painting 61 2.12 Focus Management 61 KeyboardFocusManager 64, Key events and focus management 64, Focus and Window events 64, Focusability and traversal policies 65 2.13 Keyboard input 66 Listening for keyboard input 66, KeyStrokes 67, Scopes 68, Actions 68, InputMaps and ActionMaps 68 The flow of keyboard input 69 Part II The basics 71 3 Frames, panels, and borders 73 3.1 Frames and panels overview 73 JFrame 73, JRootPane 74, RootLayout 75, The RootPaneContainer interface 76, The WindowConstants interface 76, The WindowListener interface 76, WindowEvent 77, WindowAdapter 77, Custom frame icons 78, Centering a frame on the screen 78, Headless frames and extended frame states 79, Look and feel window decorations 79, JApplet 80, JWindow 80, JPanel 80 3.2 Borders 81 Inside borders 85 3.3 Creating a custom border 86 Understanding the code 87, Running the code 88 CONTENTS xiii 4 Layout managers 89 4.1 Layouts overview 89 LayoutManager 90, LayoutManager2 90, BoxLayout 91, Box 91, Filler 91, FlowLayout 92, GridLayout 92, GridBagLayout 92, BorderLayout 93, CardLayout 93, SpringLayout 93, JPanel 94 4.2 Comparing common layout managers 94 Understanding the code 97, Running the code 97 4.3 Using GridBagLayout 98 Default behavior of GridBagLayout 98, Introducing GridBagConstraint 98, Using the gridx, gridy, insets, ipadx and ipady constraints 99, Using weightx and weighty constraints 100, Using gridwidth and gridheight constraints 101, Using anchor constraints 102, Using fill constraints 103, Putting it all together: constructing a complaints dialog 104, A simple helper class example 109 4.4 Choosing the right layout 114 Understanding the code 119, Running the code 121 4.5 Custom layout manager, part I: labels/field pairs 121 Understanding the code 125, Running the code 128 4.6 Custom layout manager, part II: common interfaces 128 Understanding the code 136, Running the code 139 4.7 Dynamic layout in a JavaBeans container 140 Understanding the code 151, Running the code 153 5 Labels and buttons 155 5.1 Labels and buttons overview 155 JLabel 155, Text alignment 157, Icons and icon alignment 158, GrayFilter 158, The labelFor and the displayedMnemonic properties 158, AbstractButton 158, The ButtonModel interface 159, JButton 159, JToggleButton 161, ButtonGroup 161, JCheckBox and JRadioButton 162, JToolTip and ToolTipManager 163, Labels and buttons with HTML text 163 5.2 Custom buttons, part I: transparent buttons 165 Understanding the code 168, Running the code 170 5.3 Custom buttons, part II: polygonal buttons 171 Understanding the code 176, Running the code 178 5.4 Custom buttons, part III: tooltip management 180 Understanding the code 183, Running the code 186 xiv CONTENTS 6 Tabbed panes 187 6.1 JTabbedPane 187 6.2 A dynamically changeable tabbed pane 189 Understanding the code 195, Running the code 196, Interesting JTabbedPane characteristics 197 6.3 Tab validation 197 Understanding the code 200 7 Scrolling panes 202 7.1 JScrollPane 202 The ScrollPaneConstants interface 204, JViewport 204, ScrollPaneLayout 206, The Scrollable interface 209 7.2 Grab-and-drag scrolling 211 Understanding the code 212 7.3 Scrolling programmatically 213 Understanding the code 217, Running the code 219 8 Split panes 220 8.1 JSplitPane 220 8.2 Basic split pane example 221 Understanding the code 223, Running the code 224 8.3 Synchronized split pane dividers 224 Understanding the code 226, Running the code 226 9 Combo boxes 227 9.1 JComboBox 227 The ComboBoxModel interface 230, The MutableComboBoxModel interface 230, DefaultComboBoxModel 230, The ListCellRenderer interface 231, DefaultListCellRenderer 231, The ComboBoxEditor interface 231 9.2 Basic JComboBox example 232 Understanding the code 237, Running the code 238 9.3 Custom model and renderer 238 Understanding the code 243, Running the code 245 9.4 Combo boxes with memory 246 Understanding the code 250, Running the code 252 9.5 Custom editing 253 Understanding the code 255, Running the code 255 CONTENTS xv 10 List boxes and Spinners 256 10.1 JList 256 The ListModel interface 259, AbstractListModel 259, DefaultListModel 259, The ListSelectionModel interface 259, DefaultListSelectionModel 260, The ListCellRenderer interface 260, The ListDataListener interface 261, ListDataEvent 261, The ListSelectionListener interface 261, ListSelectionEvent 261 10.2 Basic JList example 261 Understanding the code 263, Running the code 263 10.3 Custom rendering 264 Understanding the code 271, Running the code 273 10.4 Processing keyboard input and searching 273 Understanding the code 275, Running the code 276 10.5 List of check boxes 276 Understanding the code 279, Running the code 281 10.6 JSpinner 281 The SpinnerModel interface 282, AbstractSpinnerModel 283 SpinnerDateModel 283, SpinnerListModel 283 SpinnerNumberModel 283 10.7 Using JSpinner to select numbers 283 Understanding the code 284, Running the code 284 10.8 Using JSpinner to select dates 285 Understanding the code 286, Running the code 286 10.9 Using JSpinner to select a value from a list 286 Understanding the code 287, Running the code 287 10.10 Extending the functionality of JSpinner 288 Understanding the code 292, Running the code 1 11 Text components and undo 292 11.1 Text components overview 294 JTextComponent 292, JTextField 294, JPasswordField 298, JTextArea 298, JEditorPane 299, JTextPane 301 11.2 Using the basic text components 304 Understanding the code 305, Running the code 306 11.3 JFormattedTextField 306 JFormattedTextField.AbstractFormatter 307, DefaultFormatter 308, MaskFormatter 308, InternationalFormatter 309, DateFormatter 309, NumberFormatter 309, JFormattedTextField.AbstractFormatterFactory 309, DefaultFormatterFactory 310 11.4 Basic JFormattedTextField example 310 Understanding the code 311, Running the code 311 xvi CONTENTS 11.5 Using Formats and InputVerifier 312 InputVerifier 312, Understanding the code 318 11.6 Formatted Spinner example 319 Understanding the code 320, Running the code 320 11.7 Undo/redo 321 The UndoableEdit interface 321, AbstractUndoableEdit 321, CompoundEdit 324, UndoableEditEvent 325, The UndoableEditListener interface 325, UndoManager 325, The StateEditable interface 328, StateEdit 328, UndoableEditSupport 329, CannotUndoException 329, CannotRedoException 329, Using built-in text component undo/redo functionality 329 12 Menus, toolbars, and actions 332 12.1 Menus, toolbars, and actions overview 332 The SingleSelectionModel interface 332, DefaultSingleSelectionModel 333, JMenuBar 333, JMenuItem 333, JMenu 334, JPopupMenu 335, JSeparator 337, JCheckBoxMenuItem 337, JRadioButtonMenuItem 337, The MenuElement interface 338, MenuSelectionManager 339, The MenuDragMouseListener interface 340, MenuDragMouseEvent 340, The MenuKeyListener interface 340, MenuKeyEvent 340, The MenuListener interface 341, MenuEvent 341, The PopupMenuListener interface 341, PopupMenuEvent 341, JToolBar 341, Custom JToolBar separators 343, Changing JToolBar’s floating frame behavior 344, The Action interface 345, AbstractAction 345 12.2 Basic text editor, part I: menus 346 Understanding the code 353, Running the code 354 12.3 Basic text editor, part II: toolbars and actions 355 Understanding the code 358, Running the code 358 12.4 Basic text editor, part III: custom toolbar components 359 Understanding the code 364, Running the code 366 12.5 Basic text editor, part IV: custom menu components 366 Understanding the code 370, Running the code 371 13 Progress bars, sliders, and scroll bars 373 13.1 Bounded-range components overview 373 The BoundedRangeModel interface 373, DefaultBoundedRangeModel 374, JScrollBar 374, JSlider 375, JProgressBar 377, ProgressMonitor 381, ProgressMonitorInputStream 381 CONTENTS xvii 13.2 Basic JScrollBar example 382 Understanding the code 386, Running the code 387 13.3 JSlider date chooser 387 Understanding the code 391, Running the code 393 13.4 JSliders in a JPEG image editor 394 The JPEGDecodeParam interface 394, The JPEGEncodeParam interface 394, The JPEGImageDecoder interface 395, The JPEGImageEncoder interface 395, JPEGCodec 395, Understanding the code 403, Running the code 405 13.5 JProgressBar in an FTP client application 406 FtpClient 406, Understanding the code 414, Running the code 417 14 Dialogs 418 14.1 Dialogs and choosers overview 418 JDialog 419, JOptionPane 421, JColorChooser 425, The ColorSelectionModel interface 425, DefaultColorSelectionModel 426, AbstractColorChooserPanel 426, ColorChooserComponentFactory 427, JFileChooser 427, FileFilter 430, FileSystemView 431, FileView 431 14.2 Constructing a Login dialog 432 Understanding the code 435, Running the code 436 14.3 Adding an About dialog 436 Understanding the code 438, Running the code 439 14.4 JOptionPane message dialogs 439 Understanding the code 444 14.5 Customizing JColorChooser 445 Understanding the code 449, Running the code 450 14.6 Customizing JFileChooser 451 ZipInputStream 451, ZipOutputStream 451, ZipFile 451, ZipEntry 452, The java.util.jar package 452, Manifest 452, Understanding the code 465, Running the code 468 Part III Advanced topics 469 15 Layered panes 471 15.1 JLayeredPane 473 15.2 Using JLayeredPane to enhance interfaces 473 15.3 Creating a custom MDI 475 xviii CONTENTS 16 Desktops & internal frames 476 16.1 JDesktopPane and JInternalFrame 476 JDesktopPane 476, JInternalFrame 476, JInternalFrame.JDesktopIcon 477, The DesktopManager interface 477, DefaultDesktopManager 479, Capturing internal frame close events 479, The InternalFrameListener interface 480, InternalFrameEvent 480, InternalFrameAdapter 481, Outline dragging mode 481 16.2 Cascading and outline dragging mode 484 Understanding the code 485, Running the code 487 16.3 Adding MDI to a text editor application 487 Understanding the code 494, Running the code 495 16.4 Examples from the first edition 495 17 Trees 498 17.1 JTree 498 Tree concepts and terminology 498, Tree traversal 499, JTree 499, The TreeModel interface 500, DefaultTreeModel 501, The TreeNode interface 501, The MutableTreeNode interface 501, DefaultMutableTreeNode 501, TreePath 502, The TreeCellRenderer interface 502, DefaultTreeCellRenderer 502, CellRenderPane 503, The CellEditor interface 501, The TreeCellEditor interface 504, DefaultCellEditor 504, DefaultTreeCellEditor 504, The RowMapper interface 505, The TreeSelectionModel interface 505, DefaultTreeSelectionModel 506, The TreeModelListener interface 506, The TreeSelectionListener interface 506, The TreeExpansionListener interface 506, The TreeWillExpandListener interface 506, TreeModelEvent 507, TreeSelectionEvent 507, TreeExpansionEvent 507 ExpandVetoException 508, JTree client properties and UI defaults 508, Controlling JTree appearance 508 17.2 Basic JTree example 509 Understanding the code 513, Running the code 514 17.3 Directory tree, part I: dynamic node retrieval 514 Understanding the code 521, Running the code 526 17.4 Directory tree, part II: popup menus, programmatic navigation, node creation, renaming, and deletion 526 Understanding the code 532, Running the code 535 17.5 Directory tree, part III: tooltips 533 Understanding the code 535, Running the code 535 CONTENTS xix 18 Tables 536 18.1 JTable 536 JTable 536, The TableModel interface 538, AbstractTableModel 539, DefaultTableModel 539, TableColumn 539, The TableColumnModel interface 541, DefaultTableColumnModel 542, The TableCellRenderer interface 543, DefaultTableCellRenderer 544, The TableCellEditor interface 544, DefaultCellEditor 545, The TableModelListener interface 545, TableModelEvent 546, The TableColumnModelListener interface 546, TableColumnModelEvent 546, JTableHeader 547, JTable selection 548, Column width and resizing 550, JTable Appearance 551, JTable scrolling 552 18.2 Stocks table, part I: basic JTable example 552 Understanding the code 557, Running the code 559 18.3 Stocks table, part II: custom renderers 559 Understanding the code 563, Running the code 564 18.4 Stocks table, part III: sorting columns 564 Understanding the code 569, Running the code 570 18.5 Stocks table, part IV: JDBC 571 Understanding the code 575, Running the code 576 18.6 Stocks table, part V: column addition and removal 576 Understanding the code 579, Running the code 580 18.7 Expense report application 580 Understanding the code 589, Running the code 591 18.8 Expense report application with variable height rows 591 Understanding the code 594, Running the code 594 18.9 A JavaBeans property editor 595 Understanding the code 601, Running the code 603 19 Inside text components 605 19.1 Text package overview 605 More about JTextComponent 605, The Document interface 608, The StyledDocument interface 608, AbstractDocument 609, The Content interface 612, The Position interface 613, The DocumentEvent interface 613, The DocumentListener interface 614, The Element interface 614, PlainDocument 615, DefaultStyledDocument 617, The AttributeSet interface 620, The MutableAttributeSet interface 622, The Style interface 622, StyleConstants 623, StyleContext 623, The Highlighter interface 624, DefaultHighlighter 625, The Caret interface 625, DefaultCaret 625, The CaretListener interface 627, CaretEvent 627, The Keymap interface 627, TextAction 628, EditorKit 629, DefaultEditorKit 629, StyledEditorKit 630, View 631, The ViewFactory interface 633 xx CONTENTS 20 Constructing an HTML Editor Application 634 20.1 HTML editor, part I: introducing HTML 635 Understanding the code 641, Running the code 642 20.2 HTML editor, part II: managing fonts 642 Understanding the code 648, Running the code 650 20.3 HTML editor, part III: document properties 650 Understanding the code 664, Running the code 667 20.4 HTML editor, part IV: working with HTML styles and tables 667 Understanding the code 676, Running the code 677 20.5 HTML editor, part V: clipboard and undo/redo 677 Understanding the code 681, Running the code 682 20.6 HTML editor, part VI: advanced font management 682 Understanding the code 691, Running the code 694 20.7 HTML editor, part VII: find and replace 695 Understanding the code 704, Running the code 708 20.8 HTML editor, part IX: spell checker (using JDBC and SQL) 708 Understanding the code 718, Running the code 721 21 Pluggable look and feel 723 21.1 Pluggable look and feel overview 723 LookAndFeel 724, UIDefaults 724, UIManager 725, The UIResource interface 725, ComponentUI 726, BasicLookAndFeel 726, How look and feel works 726, Selecting a look and feel 727, Creating a custom LookAndFeel implementation 728, Defining default component resources 729, Defining class defaults 730, Creating custom UI delegates 730, Metal themes 732 21.2 Custom look and feel, part I: using custom resources 733 Understanding the code 740, Running the code 741 21.3 Custom look and feel, part II: creating custom UI delegates 741 Understanding the code 749, Running the code 751 21.4 Examples from the first edition 751 Part IV Special topics 755 22 Printing 757 22.1 Java printing overview 757 PrinterJob 758, The Printable interface 758, The Pageable interface 759, The PrinterGraphics interface 760, PageFormat 760, Paper 761, CONTENTS xxi Book 761, PrinterException 762 22.2 Printing images 762 Understanding the code 765, Running the code 767 22.3 Print preview 767 Understanding the code 773, Running the code 776 22.4 Printing text 776 Understanding the code 780, Running the code 781 22.5 Printing tables 781 Understanding the code 785, Running the code 787 23 Constructing an XML editor 789 23.1 XML editor, part I: viewing nodes 790 Understanding the code 795, Running the code 796 23.2 XML editor, part II: viewing attributes 796 Understanding the code 800, Running the code 801 23.3 XML editor, part III: editing nodes and attributes 801 Understanding the code 807, Running the code 808 23.4 XML editor, part IV: adding, editing, and removing nodes and attributes 808 Understanding the code 817, Running the code 818 23.5 XML editor, part V: custom drag and drop 818 Understanding the code 824 24 Drag and drop 826 24.1 Drag and drop overview 826 The Transferable interface 827, Clipboard 827, The ClipboardOwner interface 827, TransferHandler 828, DropTarget 829, The DropTargetListener interface 830 24.2 Adding drag and drop support within Basic Text Editor 830 Understanding the code 832, Running the code 832 24.3 Drag and drop files to Base Text Editor 832 Understanding the code 834, Running the code 834 24.4 Drag and drop with Java objects 834 Understanding the code 841, Running the code 843 A Java Web Start 845 B Resources 849 index 853
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值