?? splitpaneldemo.java
字號:
import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class SplitPanelDemo extends JFrame { JPanel contentPane=new JPanel(); JLabel jLabel1 = new JLabel(); Border border1; Component component1; JSplitPane jSplitPane1 = new JSplitPane(); JScrollPane ScrollImage = new JScrollPane(); JLabel ImageLabel = new JLabel(); JScrollPane ScrollText = new JScrollPane(); JTextArea displayArea = new JTextArea(); public SplitPanelDemo() { try {jbInit();} catch(Exception e) {} } public static void main(String[] args) { SplitPanelDemo frame = new SplitPanelDemo(); frame.setVisible(true); } //當窗口關閉時的處理代碼 protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } private void jbInit() throws Exception { //設置窗口的標題與大小 setTitle("分隔條實例演示"); setSize(new Dimension(400,300)); //取得底層容器并將其布局設為BoxLayout contentPane=(JPanel)this.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.Y_AXIS)); //設置標簽的位置與標題 jLabel1.setAlignmentX((float) 0.5); jLabel1.setText("分隔框"); //設置分隔框的位置,邊框,分隔條的大小及位置 jSplitPane1.setAlignmentX((float) 0.5); jSplitPane1.setBorder(BorderFactory.createEtchedBorder()); jSplitPane1.setDividerSize(20); jSplitPane1.setDividerLocation(100); //定義圖片并將其加入標簽中 ImageIcon dag=new ImageIcon("dog.jpg"); ImageLabel.setIcon(dag); //插入對圖片的文字說明 displayArea.setText("右邊是一條可愛\n的狗."); //將圖片及文字框加入滾動框中 ScrollText.getViewport().add(displayArea, null); ScrollImage.getViewport().add(ImageLabel, null); //分別在分隔框的右邊及左邊加入圖片及文字框 jSplitPane1.add(ScrollImage, JSplitPane.RIGHT); jSplitPane1.add(ScrollText, JSplitPane.LEFT); //加入空白邊框 border1 = BorderFactory.createEmptyBorder(10,10,10,10); contentPane.setBorder(border1); //加入標簽與垂直分隔條 contentPane.add(jLabel1, null); component1 = Box.createVerticalStrut(17); contentPane.add(component1, null); //加入分隔框 contentPane.add(jSplitPane1, null); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -