﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-日出而作兮勤于外，日落而归兮忙于内-随笔分类-Swing</title><link>http://www.blogjava.net/cherishchen/category/38421.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 02 Aug 2009 04:35:13 GMT</lastBuildDate><pubDate>Sun, 02 Aug 2009 04:35:13 GMT</pubDate><ttl>60</ttl><item><title>Layout usage scenario</title><link>http://www.blogjava.net/cherishchen/archive/2009/07/31/289272.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Fri, 31 Jul 2009 06:58:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2009/07/31/289272.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/289272.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2009/07/31/289272.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/289272.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/289272.html</trackback:ping><description><![CDATA[<dl><dt><strong>Scenario:</strong>
You need to display a component in as much space as it can get.
</dt><dd>
If it is the only component in its container,
use
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/grid.html"><code>GridLayout</code></a> or
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html"><code>BorderLayout</code></a>.
Otherwise,
<code>BorderLayout</code> or
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html"><code>GridBagLayout</code></a>
might be a good match.
<p>
If you use <code>BorderLayout</code>,
you will need to put the space-hungry component in the center.
With <code>GridBagLayout</code>,
you will need to set the constraints for the component so that
<code>fill=GridBagConstraints.BOTH</code>.
Another possibility is to use
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html"><code>BoxLayout</code></a>,
making the space-hungry component
specify very large preferred and maximum sizes.
</p>
</dd><dt><strong>Scenario:</strong>
You need to display a few components in a compact row
at their natural size.
</dt><dd>
Consider using a <code>JPanel</code> to group the components
and using either the <code>JPanel</code>'s default
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/flow.html"><code>FlowLayout</code></a> manager
or the
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html"><code>BoxLayout</code></a> manager.
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html"><code>SpringLayout</code></a>
is also good for this.
</dd><dt><strong>Scenario:</strong>
You need to display a few components of the same size
in rows and columns.
</dt><dd>
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/grid.html"><code>GridLayout</code></a> is perfect for this.
</dd><dt><strong>Scenario:</strong>
You need to display a few components in a row or column,
possibly with varying amounts of space between them,
custom alignment, or custom component sizes.
</dt><dd>
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html"><code>BoxLayout</code></a>
is perfect for this.
</dd><dt><strong>Scenario:</strong>
You need to display aligned columns,
as in a form-like interface
where a column of labels
is used to describe text fields in an adjacent column.
</dt><dd>
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html"><code>SpringLayout</code></a>
is a natural choice for this.
The <code>SpringUtilities</code> class
used by several Tutorial examples
defines a <code>makeCompactGrid</code> method
that lets you easily align multiple rows and columns of components.
</dd><dt><strong>Scenario:</strong>
You have a complex layout with many components.
</dt><dd>
Consider either using
a very flexible layout manager such as
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html"><code>GridBagLayout</code></a> or
<a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html"><code>SpringLayout</code></a>,
or grouping the components into one or more <code>JPanel</code>s
to simplify layout.
If you take the latter approach,
each <code>JPanel</code> might use a different layout manager.
</dd></dl>
<img src ="http://www.blogjava.net/cherishchen/aggbug/289272.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2009-07-31 14:58 <a href="http://www.blogjava.net/cherishchen/archive/2009/07/31/289272.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使得Jtextpane自动滚动的方法</title><link>http://www.blogjava.net/cherishchen/archive/2009/03/20/260969.html</link><dc:creator>凭栏观海</dc:creator><author>凭栏观海</author><pubDate>Fri, 20 Mar 2009 02:01:00 GMT</pubDate><guid>http://www.blogjava.net/cherishchen/archive/2009/03/20/260969.html</guid><wfw:comment>http://www.blogjava.net/cherishchen/comments/260969.html</wfw:comment><comments>http://www.blogjava.net/cherishchen/archive/2009/03/20/260969.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cherishchen/comments/commentRss/260969.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cherishchen/services/trackbacks/260969.html</trackback:ping><description><![CDATA[<br />
resultPane.getDocument().addDocumentListener(new DocumentListener() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void insertUpdate(DocumentEvent e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;resultPane.setCaretPosition(resultPane.getDocument().getLength());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void removeUpdate(DocumentEvent e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //do nothing<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void changedUpdate(DocumentEvent e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //do nothing<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br />
<br />
<img src ="http://www.blogjava.net/cherishchen/aggbug/260969.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cherishchen/" target="_blank">凭栏观海</a> 2009-03-20 10:01 <a href="http://www.blogjava.net/cherishchen/archive/2009/03/20/260969.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>