JSplitPane Dividender OneTouchExpandable

Status
Nicht offen für weitere Antworten.
G

Guest

Gast
Hallo,

ich benutze zwei JSplitPane in meinem Programm und hab für beide oneTouchExpandable aktiviert, funktioniert auch.
Kann man diese Eigenschaft auch über Code nachbilden? Ich möchte einen Button hinzufügen und wenn dieser gedrückt wird, sollen beide Divider ganz nach links bzw unten verschwinden und beim nochmaligen Klick wieder auf die ursprüngliche Position fahren.

Mit setDividerLocation(0) funktioniert es nicht wirklich, weil wenn ich das Fenster maximiere, verschiebt sich der Divider leicht.
 
G

Guest

Gast
Also ich habe mir mal den Quelltext aus der BasicSplitPaneDivider.java-Datei angeschaut und versucht das für mich anzupassen.

Ich hab dem Button, welcher dann auf Knopfdruck den Divider verschwinden lassen soll, den ActionListener zugewiesen:
Code:
private class OneTouchActionHandler implements ActionListener {
		/**
		 * True indicates the resize should go the minimum (top or left) vs
		 * false which indicates the resize should go to the maximum.
		 */
		private boolean toMinimum;

		OneTouchActionHandler(boolean toMinimum) {
			this.toMinimum = toMinimum;
		}

		public void actionPerformed(ActionEvent e) {
			Insets insets = splitPaneUI.getSplitPane().getInsets();
			int lastLoc = splitPaneUI.getSplitPane().getLastDividerLocation();
			int currentLoc = splitPaneUI.getDividerLocation(splitPaneUI
					.getSplitPane());
			int newLoc;

			// We use the location from the UI directly, as the location the
			// JSplitPane itself maintains is not necessarly correct.
			if (toMinimum) {
				if (orientation == JSplitPane.VERTICAL_SPLIT) {
					if (currentLoc >= (splitPaneUI.getSplitPane().getHeight()
							- insets.bottom - getHeight())) {
						int maxLoc = splitPaneUI.getSplitPane()
								.getMaximumDividerLocation();
						newLoc = Math.min(lastLoc, maxLoc);
						 splitPaneUI.setKeepHidden(false);
						 
					} else {
						newLoc = insets.top;
						// splitPaneUI.setKeepHidden(true);
					}
				} else {
					if (currentLoc >= (splitPaneUI.getSplitPane().getWidth()
							- insets.right - getWidth())) {
						int maxLoc = splitPaneUI.getSplitPane()
								.getMaximumDividerLocation();
						newLoc = Math.min(lastLoc, maxLoc);
						// splitPaneUI.setKeepHidden(false);
					} else {
						newLoc = insets.left;
						// splitPaneUI.setKeepHidden(true);
					}
				}
			} else {
				if (orientation == JSplitPane.VERTICAL_SPLIT) {
					if (currentLoc == insets.top) {
						int maxLoc = splitPaneUI.getSplitPane()
								.getMaximumDividerLocation();
						newLoc = Math.min(lastLoc, maxLoc);
						// splitPaneUI.setKeepHidden(false);
					} else {
						newLoc = splitPaneUI.getSplitPane().getHeight()
								- getHeight() - insets.top;
						// splitPaneUI.setKeepHidden(true);
					}
				} else {
					if (currentLoc == insets.left) {
						int maxLoc = splitPaneUI.getSplitPane()
								.getMaximumDividerLocation();
						newLoc = Math.min(lastLoc, maxLoc);
						// splitPaneUI.setKeepHidden(false);
					} else {
						newLoc = splitPaneUI.getSplitPane().getWidth()
								- getWidth() - insets.left;
						// splitPaneUI.setKeepHidden(true);
					}
				}
			}
			if (currentLoc != newLoc) {
				splitPaneUI.getSplitPane().setDividerLocation(newLoc);
				// We do this in case the dividers notion of the location
				// differs from the real location.
				splitPaneUI.getSplitPane().setLastDividerLocation(currentLoc);
			}
		}
	}

Die zeilen
Code:
splitPaneUI.setKeepHidden(true);
sind auskommentiert, weil die Funltion setKeepHidden() in der Klasse BasicSplitPaneUI.java nicht public ist. Ich weiß allerdings nicht, wie ich das umgehen kann. Hat jmd. von euch schonmal damit Erfahrungen gemacht?
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben