当OneTouchExpandable设置为true时,如何以编程方式设置JSplitPane以隐藏右/底组件? [英] how can you programmatically set the JSplitPane to hide the right/bottom component when OneTouchExpandable is set to true?

查看:163
本文介绍了当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);
            }
        });
    }
}








用1.0替换0.0并且你得到我的问题

replace 0.0 with 1.0 and you get my problem

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

Read the fine manual and solve the problem.


此方法会立即根据当前大小更改拆分窗格的大小。 如果拆分窗格未正确实现 并且在屏幕上,此方法将 无效 ...

This method immediately changes the size of the split pane based on its current size. If the split pane is not correctly realized and on screen, this method will have no effect ...

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以隐藏右/底组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆