⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splitpaneldemo.java

📁 面板、菜单、工具栏
💻 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 + -