TreeDrawer is now centered when opened

java11
Sandy Brownlee 2 years ago
parent d45c2339e1
commit e6487369ef
  1. 22
      Triangle.Compiler/src/main/java/triangle/treeDrawer/DrawerFrame.java

@ -16,13 +16,20 @@ package triangle.treeDrawer;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
class DrawerFrame extends JFrame {
/**
@ -49,6 +56,19 @@ class DrawerFrame extends JFrame {
}
});
Container contentPane = getContentPane();
contentPane.add(new JScrollPane(panel));
final JScrollPane jScrollPane = new JScrollPane(panel);
contentPane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
jScrollPane.getHorizontalScrollBar().setValue(jScrollPane.getHorizontalScrollBar().getMaximum());
jScrollPane.getHorizontalScrollBar().setValue(jScrollPane.getHorizontalScrollBar().getValue() / 2);
}
});
contentPane.add(jScrollPane);
}
}