Chapter 18 Containers, Layout Managers, and Borders ScrollPane Tab JTabbedPane Separation pane JSplitPane Swing border Menu (emphasis) Pop-up menu Toolbar JToolBar Using Action Interface to Handle Behavior Events Dialog Box JOption Pane Create a custom dialog box Colour dialog JColor Chooser File Dialog Box JFile Chooser Java高级程序设计(下) 1 ScrollPane It can be seen as a special container for any component.Imp lementation of ScrollPaneConstants 列首组件 角组件 角组件 JViewport 行首组件 角组件 可滚动组件 水平滚动条 Java高级程序设计(下) 垂直滚动条 角组件 2 ScrollPane // Display a text field in the viewport JTextArea JB = new JTextArea (500,600); JScrollPane JS = new JScrollPane (jb); // Set the border of the viewport Js. setViewportBorder (new LineBorder (Color. red, 3)); // Setting up row components Js. setRowHeaderView (new JLabel ("rowheader"); // Setting Column Components Js. setColumn HeaderView (new JLabel ("columnheader"); // Setting Angle Component Js. setCorner (JScrollPane. UPPER_LEFT_CORNER, New Corner (JScrollPane. UPPER_LEFT_CORNER); Java高级程序设计(下) 3 Tab JTabbedPane, Separator Pane JSplitPane JTabbedPane class: Allows users to switch between a set of components by clicking a tab with a g iven title and/or icon. Example: jtabbed. Java JSplitPane class: Construction method: Public JSplitPane (int new Orientation, Boolean new Continuous Layout) Create a new JSplitPane with the specified direction and redraw mode New Orientation: HORIZONTAL_SPLIT or JSplitPane.VERTICAL_SPLIT New Continuous Layout: true/false JSplitPane (int new Orientation, Component new Left Component, Compone nt new Right Component) Create a new JSplitPane with specified components with specified directions and discontinuous redrawing. Java高级程序设计(下) 4 Swing border You can decorate the borders of components, s uch as line Border, titled Border Java高级程序设计(下) 5 menu Java provides five classes for implementing menus: JMenuBar, JMenu, JMenuItem, JCheckBox MenuItem, JRadio Button MenuItem JMenuBar: The top-level menu component used to store menus. Steps to create a menu: Create a menu bar and use the setJMenuBar method to establish its association with a framework or applet.  Create menus, use add, and associate them with menu bars.  Add (JMenu C) Create menu items, use add (JMenuItem menuItem) and add the m to the menu.  Menu items generate ActionEvent events. The program must i mplement the listener class ActionListener interface in order t o select events from the corresponding menu. Java高级程序设计(下) 6 menu Set icons and hotkeys for the following menus: JMenu, JMenuItem, JCheckBox MenuItem, JRadio Button Menu Item The method of use is as follows: SetIcon (Icon i); // Set Icon Set Mnemonic (int mnemonic)//Set hotkeys SetAccelerator (KeyStroke keyStroke) // Set shortcuts Acquisition of KeyStroke instances: The static method getKeyStroke (int i, int j) using KeyStroke is as follows: KeyStroke. getKeyStroke ( KeyEvent. VK_I, ActionEvent. CTRL_MASK); Example: Create a user interface that can perform arithmetic operations.Th e interface contains labels and text fields for operands Number1 and nu mber2 and result result of operations. For example: menu. Java Java高级程序设计(下) 7 Pop-up menu Example: Create pop-up menus and add menu items JPopupMenu JPOP = new JPopupMenu (); Jpop. add (new); Using the show method, a parent component of the pop-up menu is asso ciated and displayed. For example: jpop. show (Component invoker, int x, int y) A pop-up menu is usually displayed when you point to an invoker object and click the mouse button. Method 1: Implement the mouse monitor interface. Method 2: Use the following method in JComponent: Public void setComponent PopupMenu (JPopupMenu popup) This method will add pop-up menus to components and automatically p rocess the monitored mouse events.But this method can not be used with JPanel. Example: popmenu. Java Java高级程序设计(下) 8 Toolbar JToolBar Toolbar: Usually used to store commands in menus. JToolBar property: Orientation: JToolBar. HORIZONTAL / JToolBar. VERTICA L Floatable: Indicates whether the toolbar can float.The de fault is true. The JToolBar instance is a common container. Example: tool. Java Java高级程序设计(下) 9 Using Action Interface to Handle Behavior Events Swing provides an Action interface that can centralize co mmon behavior and separate it from other code. The inheritance relationship of the Action interface: ActionListener-Action-AbstractAction Javax. swing. Action GetValue (key: String): Object IsEna

pptDoc Java container layout manager and border

Professional Docs > Common > Other > Preview
18 Pages 0 Downloads 47 Views 3.0 Score
Tips: Current document can only be previewed at most page8,If the total number of pages in the document exceeds page 8,please download the document。
Uploaded by admin on 2019-10-16 00:28:54
Rate
You can enter 255 characters
What is my domain?( answer:www.45doc.com )
comments
  • No comments yet