TreeDrawer is now centered when opened
This commit is contained in:
parent
d45c2339e1
commit
e6487369ef
@ -16,13 +16,20 @@ package triangle.treeDrawer;
|
|||||||
|
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.Toolkit;
|
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.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollBar;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
class DrawerFrame extends JFrame {
|
class DrawerFrame extends JFrame {
|
||||||
/**
|
/**
|
||||||
@ -49,6 +56,19 @@ class DrawerFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
Container contentPane = getContentPane();
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user