Java GUI 问题 [英] Java GUI Problems

查看:33
本文介绍了Java GUI 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个非常简单的 GUI,但没有任何运气.基本上,外部布局有两列,它们是一个拆分器窗格(这是我正在编写的 IRC 客户端).左侧是服务器/频道/用户树,右侧是聊天窗格.现在我将其分解为右侧,顶部是输出窗格,底部是单行输入框.

I'm designing a really simple GUI but without any luck. Basically the outer layout has two columns which is a splitter pane (this is for an IRC client I'm writing). On the left-hand side is the server/channel/user tree and on the right is the chat pane. Now I break this down so on the right-hand side there's the output pane at the top, and a single-lined input box at the bottom.

这是整体创建GUI的代码(这只是一个片段)

This is the code for creating the GUI on a whole (this is just a snippet)

ChatModel cm = new ChatModel();
ChatView cv = new ChatView(cm);

treeViewChatSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, serverTreeView, cv);
treeViewChatSplitPane.setSize(500, 500);
treeViewChatSplitPane.setBorder(null);
treeViewChatSplitPane.setDividerSize(3);
this.getContentPane().add(treeViewChatSplitPane);

this.setSize(500, 500);

ChatView 构造函数中有这个(它扩展了 java.awt.Container)

The ChatView constructor has this in it (it extends java.awt.Container)

this.model = model;
this.setLayout(new BorderLayout());

mainTextArea = new JTextArea();
mainTextArea.setLineWrap(true);
mainTextArea.setBackground(new Color(255, 255, 255));

inputField = new JTextField();

this.add(mainTextArea, BorderLayout.CENTER);
this.add(inputField, BorderLayout.PAGE_END);

现在最初看起来不错,但我遇到的问题是您可以将拆分器移至左侧,但不能移至右侧.事实上,如果你向左移动它,你就不能再向右移动它.我之前确实让它工作过,但实施起来不太好,我已经忘记了我做了什么.

Now it looks fine initially, but the problem I'm having with it is that you can move the splitter to the left, but not to the right. In fact, if you move it left, you can no longer move it right. I did have it working earlier, but the implementation wasn't as good and I've forgotten what I had done.

有什么想法吗?我不明白为什么这不起作用.

Any ideas? I can't see why this wouldn't work.

推荐答案

如果我没记错的话,JSplitPanes 总是尊重其组件的最小尺寸.尝试将 ChatView 的最小尺寸显式设置为 (0,0),看看是否有帮助.如果是这样,您可以查看其中的每个组件,看看是哪个组件导致了问题.

If I remember correctly, JSplitPanes always respect the minimum size of their components. Try explicitly setting the minimum size of the ChatView to (0,0) and see if that helps. If so, you can then look at each of the components inside it to see which is causing the problem.

这篇关于Java GUI 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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