Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ComponentAdapter;
- import java.awt.event.ComponentEvent;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.util.Random;
- import javax.swing.JFrame;
- import javax.swing.JSplitPane;
- import javax.swing.JTextArea;
- public class SplitTwo extends JFrame {
- volatile JSplitPane sp;
- JTextArea ta1, ta2;
- private boolean listener;
- Random rand;
- public SplitTwo() {
- rand = new Random();
- listener = true;
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setVisible(true);
- ta1 = new JTextArea();
- ta2 = new JTextArea();
- sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, ta1, ta2);
- setupSP();
- this.add(sp);
- this.pack();
- }
- public void setupSP() {
- sp.addComponentListener(new ComponentAdapter() {
- @Override
- public synchronized void componentResized(ComponentEvent e) {
- synchronized (this) {
- listener = false;
- setDividerLocation();
- listener = true;
- }
- }
- });
- sp.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
- new PropertyChangeListener() {
- @Override
- public synchronized void propertyChange(
- PropertyChangeEvent e) {
- synchronized (this) {
- if (listener) {
- System.out.println("Listener is: " + listener
- + " foo " + sp.getDividerLocation());
- }
- }
- }
- });
- }
- public void setDividerLocation() {
- System.out.println("\t" + listener);
- sp.setDividerLocation(rand.nextInt((int) sp.getSize().getHeight()));
- System.out.println("\t" + listener);
- }
- public static void main(String[] args) {
- new SplitTwo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement