Ade*_*ros 4 java swing jsplitpane
在a中JSplitPane,您可以使用setOneTouchExpandable方法为您提供2个按钮,以便快速完全隐藏或完全显示JSplitPane.
我的问题是你怎么能以编程方式"点击"隐藏按钮JSplitPane?
我可能错误地解释了自己.我希望splitpane在开始时只显示2个组件中的一个(这就是我点击的意思).
这有效:
import javax.swing.*;
class SplitPaneDefault {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JSplitPane sp = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JTree(),
new JTree());
sp.setOneTouchExpandable(true);
sp.setDividerLocation(0.0);
JOptionPane.showMessageDialog(null, sp);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
但将0.0有1.0不躲右组件.这是我的问题!
import javax.swing.*;
class SplitPaneDefault {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JSplitPane sp = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JTree(),
new JTree());
sp.setOneTouchExpandable(true);
sp.setDividerLocation(0.0);
JOptionPane.showMessageDialog(null, sp);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
用1.0替换0.0,你就得到了我的问题
阅读精细手册并解决问题.
此方法会立即根据其当前大小更改拆分窗格的大小.如果未正确实现拆分窗格并且在屏幕上,此方法将无效 ...

import javax.swing.*;
class SplitPaneDefault {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JSplitPane sp = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JTree(),
new JTree());
sp.setOneTouchExpandable(true);
JFrame f = new JFrame("Split Pane To Right");
f.add(sp);
f.pack();
// sp now has a non-zero size!
sp.setDividerLocation(1.0);
f.setLocationByPlatform(true);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setVisible(true);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6693 次 |
| 最近记录: |