Rabu, 13 Agustus 2025

JAVA - Split Pane



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tjsplitpane;
import javax.swing.*;
import java.awt.*;

public class TJSplitPane extends JApplet {
    static int HORIZSPLIT = JSplitPane.HORIZONTAL_SPLIT;
    static int VERTSPLIT = JSplitPane.VERTICAL_SPLIT;
    boolean continuousLayout = true;
    Icon icon1 = new ImageIcon("a.gif");
    Icon icon2 = new ImageIcon("a.gif");
    Icon icon3 = new ImageIcon("a.gif");

    public void init() {
        // 1. Create a label to display icon1 and add it to a scroll pane.    
        JLabel label1 = new JLabel(icon1);
        JScrollPane topLeftComp = new JScrollPane(label1);
        
        // 2. Create another lable to display icon2 and add it to another scroll pane.
        JLabel label2 = new JLabel(icon2);
        JScrollPane bottomLeftComp = new JScrollPane(label2);
        
        // 3. Create a third label to display icon3 and add it to one more scroll pane.
        JLabel label3 = new JLabel(icon3);
        JScrollPane rightComp = new JScrollPane(label3);
    
        // 4. Add the scroll panes displaying icon1 and icon2 to a split pane.
        JSplitPane splitPane1 = new JSplitPane(VERTSPLIT,
                                          continuousLayout,
                                          topLeftComp,
                                          bottomLeftComp);
        splitPane1.setOneTouchExpandable(true); // Provide a collapse/expand widget.
        splitPane1.setDividerSize(2); // Divider size.
        splitPane1.setDividerLocation(0.5); // Initial location of the divider.
        
        // 5. Add the previous split pane and the scroll pane displaying 
        // icon3 to an outer split pane.
        JSplitPane splitPane2 = new JSplitPane(HORIZSPLIT,                                        
                                          splitPane1, // left comp
                                          rightComp);
        splitPane2.setOneTouchExpandable(true); // Provide a collapse/expand widget.
        splitPane2.setDividerLocation(0.4); // divider size 
        splitPane2.setDividerSize(2); // Initial location of the divider.
           
        // 6. Add the outer split pane to the content pane of the applet.                             
        getContentPane().add(splitPane2);                                 
    }
}


 



Tidak ada komentar: