📄 problems.html
字号:
<div class="linkBHEAD"><a href="applet.html">How to Make Applets</a></div><div class="linkBHEAD"><a href="button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a></div><div class="linkBHEAD"><a href="colorchooser.html">How to Use Color Choosers</a></div><div class="linkBHEAD"><a href="combobox.html">How to Use Combo Boxes</a></div><div class="linkBHEAD"><a href="dialog.html">How to Make Dialogs</a></div><div class="linkBHEAD"><a href="editorpane.html">How to Use Editor Panes and Text Panes</a></div><div class="linkBHEAD"><a href="filechooser.html">How to Use File Choosers</a></div><div class="linkBHEAD"><a href="formattedtextfield.html">How to Use Formatted Text Fields</a></div><div class="linkBHEAD"><a href="frame.html">How to Make Frames (Main Windows)</a></div><div class="linkBHEAD"><a href="internalframe.html">How to Use Internal Frames</a></div><div class="linkBHEAD"><a href="label.html">How to Use Labels</a></div><div class="linkBHEAD"><a href="layeredpane.html">How to Use Layered Panes</a></div><div class="linkBHEAD"><a href="list.html">How to Use Lists</a></div><div class="linkBHEAD"><a href="menu.html">How to Use Menus</a></div><div class="linkBHEAD"><a href="panel.html">How to Use Panels</a></div><div class="linkBHEAD"><a href="passwordfield.html">How to Use Password Fields</a></div><div class="linkBHEAD"><a href="progress.html">How to Use Progress Bars</a></div><div class="linkBHEAD"><a href="rootpane.html">How to Use Root Panes</a></div><div class="linkBHEAD"><a href="scrollpane.html">How to Use Scroll Panes</a></div><div class="linkBHEAD"><a href="separator.html">How to Use Separators</a></div><div class="linkBHEAD"><a href="slider.html">How to Use Sliders</a></div><div class="linkBHEAD"><a href="spinner.html">How to Use Spinners</a></div><div class="linkBHEAD"><a href="splitpane.html">How to Use Split Panes</a></div><div class="linkBHEAD"><a href="tabbedpane.html">How to Use Tabbed Panes</a></div><div class="linkBHEAD"><a href="table.html">How to Use Tables</a></div><div class="linkBHEAD"><a href="textarea.html">How to Use Text Areas</a></div><div class="linkBHEAD"><a href="textfield.html">How to Use Text Fields</a></div><div class="linkBHEAD"><a href="toolbar.html">How to Use Tool Bars</a></div><div class="linkBHEAD"><a href="tooltip.html">How to Use Tool Tips</a></div><div class="linkBHEAD"><a href="tree.html">How to Use Trees</a></div><div class="linkAHEAD"><a href="icon.html">How to Use Icons</a></div><div class="linkAHEAD"><a href="border.html">How to Use Borders</a></div><div class="nolinkAHEAD">Solving Common Component Problems</div></div> </div> <div id=MainFlow class=MainFlow_indented> <span id=BreadCrumbs> <a href=../../index.html target=_top>Home Page</a> > <a href=../index.html target=_top>Creating a GUI with JFC/Swing</a> > <a href=index.html target=_top>Using Swing Components</a> </span> <div class=NavBit> <a target=_top href=border.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=../QandE/questions-ch3.html>Next »</a> </div> <div id=PageTitle>Solving Common Component Problems</div> <blockquote>This section discusses problems that you might encounterwhile using components.If you don't find your problem in this section,consultthe following sections:<ul><li><a class="TutorialLink" target="_top" href="../misc/problems.html">Solving Common Problems Using Other Swing Features</a><li><a class="TutorialLink" target="_top" href="../layout/problems.html">Solving Common Layout Problems</a><li><a class="TutorialLink" target="_top" href="../events/problems.html">Solving Common Event-Handling Problems</a><li><a class="TutorialLink" target="_top" href="../painting/problems.html">Solving Common Painting Problems</a></ul><p><strong>Problem:</strong> I'm having trouble implementing a model(or some other code that's similar to something already in Java SE Platform, Standard Edition).<ul><li> Look at the Java SE source code.It's distributed with the JDK,and it's a great resource for finding code examplesof implementing models, firing events, and the like.</ul><strong>Problem:</strong> Whenever the text in my text field updates,the text field's size changes.<ul><li> You should specify the preferred width of the text field by specifying the number of columns it should have room to display. To do this, you can use either an <code>int</code> argument to the <code>JTextField</code> constructor or the <code>setColumns</code> method.</ul><strong>Problem:</strong> Certain areas of the content pane look weird when they're repainted.<ul><li> If you set the content pane, make sure it's opaque. You can do this by invoking <code>setOpaque(true)</code> on your content pane. Note that although <code>JPanel</code>s are opaque in most look and feels, that's not true in the GTK+ look and feel. See <a href="toplevel.html#contentpane">Adding Components to the Content Pane</a> for details.<li> If one or more of your components performs custom painting, make sure you implemented it correctly. See<a class="TutorialLink" target="_top" href="../painting/problems.html">Solving Common Painting Problems</a> for help.<li> You might have a thread safety problem. See the next entry.</ul><p><strong>Problem:</strong> My program is exhibiting weird symptomsthat sometimes seem to be related to timing.<ul><li> Make sure your code is thread-safe. See<a class="TutorialLink" target="_top" href="../concurrency/index.html">Concurrency in Swing</a> for details.</ul><p><strong>Problem:</strong>My modal dialog gets lost behind other windows.<ul><li> If the dialog has a null parent component, try setting it to a valid frame or component when you create it.<li> This bug was fixed in the 6.0 release. For more information, see<a class="OutsideLink" target="_blank" href="http://developer.java.sun.com/developer/bugParade/bugs/4255200.html">4255200</a>.</ul><p><strong>Problem:</strong>The scroll bar policies don't seem to be working as advertised.<ul><li> Some Swing releases contain bugs in the implementations for the <code>VERTICAL_SCROLLBAR_AS_NEEDED</code> and the <code>HORIZONTAL_SCROLLBAR_AS_NEEDED</code> policies. If feasible for your project, use the most recent release of Swing.<li> If the scroll pane's client can change size dynamically, the program should set the client's preferred size and then call <code>revalidate</code> on the client.<li> Make sure you specified the policy you intended for the orientation you intended.</ul><strong>Problem:</strong>My scroll pane has no scroll bars.<ul><li> If you want a scroll bar to appear all the time, specify either <code>VERTICAL_SCROLLBAR_ALWAYS</code> or <code>HORIZONTAL_SCROLLBAR_ALWAYS</code> for the scroll bar policy as appropriate.<li> If you want the scroll bars to appear as needed, and you want to force the scroll bars to be needed when the scroll pane is created, you have two choices: either set the preferred size of scroll pane or its container, or implement a scroll-savvy class and return a value smaller than the component's standard preferred size from the <code>getPreferredScrollableViewportSize</code> method. Refer to <a href="scrollpane.html#sizing">Sizing a Scroll Pane</a> for information.</ul><strong>Problem:</strong>The divider in my split pane don't move!<ul><li> You need to set the minimum size of at least one of the components in the split pane. Refer to <a href="splitpane.html#divider">Positioning the Divider and Restricting Its Range</a> for information.</ul><strong>Problem:</strong>The <code>setDividerLocation</code> method of <code>JSplitPane</code>doesn't work.<ul><li> The <code>setDividerLocation(double)</code> method has no effect if the split pane has no size (typically true if it isn't onscreen yet). You can either use <code>setDividerLocation(int)</code> or specify the preferred sizes of the split pane's contained components and the split pane's resize weight instead. Refer to <a href="splitpane.html#divider">Positioning the Divider and Restricting Its Range</a> for information.</ul><a name="nestedborders"><strong>Problem:</strong>The borders on nested split panes look too wide.<ul><li> If you nest split panes, the borders accumulate — the border of the inner split panes display next to the border of the outer split pane causing borders that look extra wide. The problem is particularly noticeable when nesting many split panes. The workaround is to set the border to null on any split pane that is placed within another split pane. For information, see bug #<a class="OutsideLink" target="_blank" href="http://developer.java.sun.com/developer/bugParade/bugs/4131528.html">4131528</a> in the Bug Database at the Sun Developer Network (SDN).</ul></a><strong>Problem:</strong>The buttons in my tool bar are too big.<ul><li> Try reducing the margin for the buttons. For example:<blockquote><pre>button.setMargin(new Insets(0,0,0,0));</pre></blockquote></ul><a name="layeredpane"><strong>Problem:</strong></a>The components in my layered panearen't layered correctly.In fact, the layers seem to be inversed — thelower the depth the higher the component.<ul><li> This can happen if you use an <code>int</code> instead of an <code>Integer</code> when adding components to a layered pane. To see what happens, make the following change to <code>LayeredPaneDemo</code>:<p><table border=1><tr><th>Change this...</th><th>to this...</th></tr><tr><td><code>layeredPane.add(label, new Integer(i));</code></td><td><code>layeredPane.add(label, <strong>i</strong>);</code></td></tr></table></ul><p><strong>Problem:</strong>The method call <code><em>colorChooser</em>.setPreviewPanel(null)</code> does not remove the color chooser's preview panel as expected.<ul><li> A <code>null</code> argument specifies the default preview panel. To remove the preview panel, specify a standard panel with no size, like this: <code><em>colorChooser</em>.setPreviewPanel(new JPanel());</code></ul><p> </blockquote> <div class=NavBit> <a target=_top href=border.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=../QandE/questions-ch3.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use Borders <br><b>Next page:</b> Questions and Exercises: Using Swing Components </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -