本文介绍了当OneTouchExpandable设置为true时,如何以编程方式设置JSplitPane以隐藏右/底组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSplitPane 中,你有 setOneTouchExpandable 方法,该方法为你提供2个按钮,可以快速完全隐藏或完整显示 JSplitPane

In a JSplitPane, you have the setOneTouchExpandable method which provides you with 2 buttons to quickly fully hide or full show the JSplitPane.

我的问题是你怎么能以编程方式点击隐藏按钮上的 JSplitPane

My question is how can you programmatically "click" the hide button on the JSplitPane?

我可能错误地解释了自己。我希望splitpane在开始时只显示2个组件中的一个(这就是我点击的意思)。

I may have wrongly explained myself. I want the splitpane to show only one of the 2 components at start (this is what i mean by clicking).

此作品:

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);
            }
        });
    }
}

但替换 0.0 1.0 不会隐藏正确的组件。这是我的问题!

but replacing 0.0 with 1.0 doesn't hide the right component. This is my problem!

推荐答案

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);
            }
        });
    }
}







阅读精细手册并解决问题。

Read the fine manual and solve the problem.

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);
            }
        });
    }
}

这篇关于当OneTouchExpandable设置为true时,如何以编程方式设置JSplitPane以隐藏右/底组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 23:00