Documentation

The Java™ Tutorials
Hide TOC
Solving Common Component Problems解决常见组件问题
Trail: Creating a GUI With Swing
Lesson: Using Swing Components

Solving Common Component Problems解决常见组件问题

This section discusses problems that you might encounter while using components. 本节讨论使用组件时可能遇到的问题。If you do not find your problem in this section, consult the following sections:如果您在本节中没有找到问题,请参阅以下部分:

Problem: I am having trouble implementing a model (or some other code that is similar to something already in Java SE Platform, Standard Edition).我在实现模型(或与JavaSE平台标准版中已有的代码类似的其他代码)时遇到了问题。

Problem: Whenever the text in my text field updates, the text field's size changes.每当文本字段中的文本更新时,文本字段的大小就会改变。

Problem: Certain areas of the content pane look weird when they are repainted.内容窗格的某些区域重新绘制时看起来很奇怪。

Problem: My program is exhibiting weird symptoms that sometimes seem to be related to timing.我的程序显示出奇怪的症状,有时似乎与时间有关。

Problem: My modal dialog gets lost behind other windows.我的模态对话框在其他窗口后面丢失。

Problem: The scroll bar policies do not seem to be working as advertised.滚动条策略似乎并不像广告所说的那样有效。

Problem: My scroll pane has no scroll bars.我的滚动窗格没有滚动条。

Problem: The divider in my split pane does not move!拆分窗格中的分隔线不移动!

Problem: The setDividerLocation method of JSplitPane does not work.JSplitPanesetDividerLocation方法不起作用。

Problem: The borders on nested split panes look too wide.嵌套拆分窗格上的边框看起来太宽。

Problem: The buttons in my tool bar are too big.我工具栏中的按钮太大了。

Problem: The components in my layered pane are not layered correctly. 分层窗格中的组件分层不正确。In fact, the layers seem to be inversed — the lower the depth the higher the component.事实上,这些层似乎是相反的—深度越低,组件越高。

Problem: The method call colorChooser.setPreviewPanel(null) does not remove the color chooser's preview panel as expected.调用colorChooser.setPreviewPanel(null)的方法没有按预期移除颜色选择器的预览面板。


Previous page: How to Use Borders
Next page: Questions and Exercises: Using Swing Components