The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
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.每当文本字段中的文本更新时,文本字段的大小就会改变。
int
argument to the JTextField
constructor or the setColumns
method.JTextField
构造函数或setColumns
方法使用int
参数。Problem: Certain areas of the content pane look weird when they are repainted.内容窗格的某些区域重新绘制时看起来很奇怪。
setOpaque(true)
on your content pane. setOpaque(true)
来实现这一点。JPanel
s are opaque in most look and feels, that is not true in the GTK+ look and feel. JPanel
在大多数外观中是不透明的,但在GTK+外观中则不是这样。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.滚动条策略似乎并不像广告所说的那样有效。
VERTICAL_SCROLLBAR_AS_NEEDED
and the HORIZONTAL_SCROLLBAR_AS_NEEDED
policies. VERTICAL_SCROLLBAR_AS_NEEDED
和HORIZONTAL_SCROLELBAR_AS-NEEDED
策略的实现中包含bug。revalidate
on the client.revalidate
。Problem: My scroll pane has no scroll bars.我的滚动窗格没有滚动条。
VERTICAL_SCROLLBAR_ALWAYS
or HORIZONTAL_SCROLLBAR_ALWAYS
for the scroll bar policy as appropriate.VERTICAL_SCROLLBAR_ALWAYS
或HORIZONTAL_SCROLELBAR_ALWAYS
。getPreferredScrollableViewportSize
method. getPreferredScrollableViewportSize
方法返回一个小于组件标准首选大小的值。Problem: The divider in my split pane does not move!拆分窗格中的分隔线不移动!
Problem: The setDividerLocation
method of JSplitPane
does not work.JSplitPane
的setDividerLocation
方法不起作用。
setDividerLocation(double)
method has no effect if the split pane has no size (typically true if it is not onscreen yet). setDividerLocation(double)
方法无效(如果尚未在屏幕上显示,则通常为true
)。setDividerLocation(int)
or specify the preferred sizes of the split pane's contained components and the split pane's resize weight instead. setDividerLocation(int)
或指定拆分窗格所包含组件的首选大小以及拆分窗格的调整大小权重。Problem: The borders on nested split panes look too wide.嵌套拆分窗格上的边框看起来太宽。
Problem: The buttons in my tool bar are too big.我工具栏中的按钮太大了。
button.setMargin(new Insets(0,0,0,0));
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.事实上,这些层似乎是相反的深度越低,组件越高。
int
instead of an Integer
when adding components to a layered pane. int
而不是Integer
,则可能发生这种情况。LayeredPaneDemo
class, change layeredPane.add(label, new Integer(i));
to layeredPane.add(label, i);
LayeredPaneDemo
类中将layeredPane.add(label, new Integer(i));
更改为layeredPane.add(label, i);
.Problem: The method call 调用colorChooser.setPreviewPanel(null)
does not remove the color chooser's preview panel as expected.colorChooser.setPreviewPanel(null)
的方法没有按预期移除颜色选择器的预览面板。
null
argument specifies the default preview panel. null
参数指定默认预览面板。colorChooser.setPreviewPanel(new JPanel());