下面列出了javax.swing.JSplitPane#getLeftComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* TODO: to remove? doesn't seems to be used anywhere.
*/
protected void updateSplitLocation(JSplitPane split, int foo) {
Component left = split.getLeftComponent();
Component right = split.getRightComponent();
if(left == null) {
split.setDividerLocation(0);
return;
}
if(right == null) {
split.setDividerLocation(1);
return;
}
Dimension leftPS = left.getPreferredSize();
Dimension rightPS = right.getPreferredSize();
double location =
split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT
? (double)leftPS.width / (leftPS.width + rightPS.width)
: (double)leftPS.height / (leftPS.height + rightPS.height);
split.setDividerLocation(location);
}
@Override
public int getMaximumDividerLocation(JSplitPane pane) {
int rightMax = super.getMaximumDividerLocation(pane);
Component first = pane.getLeftComponent();
if ((first != null) && first.isVisible()) {
Dimension maxSize = first.getMaximumSize();
Insets insets = pane.getInsets();
if (pane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
rightMax = Math.min(rightMax, maxSize.width + insets.left);
} else {
rightMax = Math.min(rightMax, maxSize.height + insets.top);
}
// Sanity check. Must be in this method, not in
// getMinimumDividerLocation() (see below)
rightMax = Math.max(rightMax, getMinimumDividerLocation(pane));
}
return rightMax;
}
/** Removes a real component from a real container.
* @param container instance of a real container
* @param containerDelegate effective container delegate of the container
* @param component component to be removed
* @return whether it was possible to remove the component (some containers
* may not support removing individual components reasonably)
*/
@Override
public boolean removeComponentFromContainer(Container container,
Container containerDelegate,
Component component)
{
if( !(containerDelegate instanceof JSplitPane) ) {
return false; // should not happen
}
JSplitPane splitPane = (JSplitPane) containerDelegate;
if( component == splitPane.getLeftComponent() ) {
if( super.removeComponentFromContainer(container, containerDelegate, component) ) {
JButton left = (JButton) splitPane.getClientProperty(LEFT_TOP_BUTTON);
if( left != null ) {
// fall back to the default swing setting
splitPane.setLeftComponent(left);
splitPane.putClientProperty(LEFT_TOP_BUTTON, null);
}
return true;
}
} else if ( component == splitPane.getRightComponent() ) {
if( super.removeComponentFromContainer(container, containerDelegate, component) ) {
JButton right = (JButton) splitPane.getClientProperty(RIGHT_BOTTOM_BUTTON);
if( right != null ) {
// fall back to the default swing setting
splitPane.setRightComponent(right);
splitPane.putClientProperty(RIGHT_BOTTOM_BUTTON, null);
}
return true;
}
}
return super.removeComponentFromContainer(container, containerDelegate, component);
}
private Component getFirstComponent(JSplitPane splitPane) {
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
return splitPane.getLeftComponent();
} else {
return splitPane.getTopComponent();
}
}
public @Override boolean requestFocusInWindow() {
JSplitPane view = getCurrentResultView();
if (view == null) {
return super.requestFocusInWindow();
}
Component left = view.getLeftComponent();
if (left == null) {
return super.requestFocusInWindow();
}
return left.requestFocusInWindow();
}
public void actionPerformed(ActionEvent e) {
JSplitPane view = getCurrentResultView();
if (view == null || !(view.getLeftComponent() instanceof StatisticsPanel)) {
return;
}
StatisticsPanel statisticsPanel = (StatisticsPanel) view.getLeftComponent();
if (next) {
statisticsPanel.selectNextFailure();
} else {
statisticsPanel.selectPreviousFailure();
}
}
private static StatisticsPanel getStatisticsPanel() {
JSplitPane view = getCurrentResultView();
if (view == null || !(view.getLeftComponent() instanceof StatisticsPanel)) {
return null;
}
return (StatisticsPanel) view.getLeftComponent();
}
private Component getFirstComponent(JSplitPane splitPane) {
if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
return splitPane.getLeftComponent();
} else {
return splitPane.getTopComponent();
}
}
private JTextArea getTextArea(){
int selIndex = getTabIndex();
if(selIndex >= 0){
TabData selTabData = tabDataModel.getTab(selIndex);
JSplitPane selSplitPane = (JSplitPane)selTabData.getComponent();
JScrollPane sp = (JScrollPane)selSplitPane.getLeftComponent();
JViewport vp = (JViewport)sp.getComponent(0);
JTextArea ta = (JTextArea)vp.getComponent(0);
return ta;
}
return null;
}
private JTree getTree(TabData tabData){
if(tabData==null){
return null;
}
JSplitPane selSplitPane = (JSplitPane)tabData.getComponent();
JSplitPane rightSplitPane = (JSplitPane)selSplitPane.getRightComponent();
JScrollPane sp = (JScrollPane)rightSplitPane.getLeftComponent();
JViewport vp = (JViewport)sp.getComponent(0);
JTree t = (JTree)vp.getComponent(0);
return t;
}
private void copyFilterMask(JSplitPane oldView, JSplitPane newView) {
StatisticsPanel oldSP = (StatisticsPanel)oldView.getLeftComponent();
StatisticsPanel newSP = (StatisticsPanel)newView.getLeftComponent();
newSP.copyFilterMask(oldSP);
}