📄 border.html
字号:
of the <a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/border/AbstractBorder.html"><code>AbstractBorder</code></a> class.In your subclass, you must implement at least one constructorand the following two methods:<ul><li> <code>paintBorder</code>, which contains the drawing code that a <code>JComponent</code> executes to draw the border.<li> <code>getBorderInsets</code>, which specifies the amount of space the border needs to draw itself.</ul>For examples of implementing borders,see the source code for the classes in the <code>javax.swing.border</code> package.</blockquote><h3><a name="api">The Border API</a></h3><blockquote>The following tables list the commonly usedborder methods.The API for using borders falls into two categories:<ul><li><a href="#createapi">Creating a Border with BorderFactory</a><li><a href="#setgetapi">Setting or Getting a Component's Border</a></ul><p><table border=1> <caption><a name="createapi">Creating a Border with BorderFactory</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createLineBorder(java.awt.Color)">Border createLineBorder(Color)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createLineBorder(java.awt.Color, int)">Border createLineBorder(Color, int)</a></td><td>Create a line border. The first argument is a <code>java.awt.Color</code> object that specifies the color of the line. The optional second argument specifies the width in pixels of the line.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createEtchedBorder()">Border createEtchedBorder()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createEtchedBorder(java.awt.Color, java.awt.Color)">Border createEtchedBorder(Color, Color)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createEtchedBorder(int)">Border createEtchedBorder(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createEtchedBorder(int, java.awt.Color, java.awt.Color)">Border createEtchedBorder(int, Color, Color)</a></td><td>Create an etched border. The optional <code>Color</code> arguments specify the highlight and shadow colors to be used. In release 1.3, methods with <code>int</code> arguments were added that allow the border methods to be specified as either <code>EtchedBorder.RAISED</code> or <code>EtchedBorder.LOWERED</code>. The methods without the <code>int</code> arguments create a lowered etched border.</tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createLoweredBevelBorder()">Border createLoweredBevelBorder()</a></td><td>Create a border that gives the illusion of the component being lower than the surrounding area.</td></tr><tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createRaisedBevelBorder()">Border createRaisedBevelBorder()</a></td><td>Create a border that gives the illusion of the component being higher than the surrounding area.</td></tr><tr><td> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createBevelBorder(int, java.awt.Color, java.awt.Color)">Border createBevelBorder(int, Color, Color)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createBevelBorder(int, java.awt.Color, java.awt.Color, java.awt.Color, java.awt.Color)">Border createBevelBorder(int, Color, Color, Color, Color)</a></td><td>Create a raised or lowered beveled border, specifying the colors to use. The integer argument can be either <code>BevelBorder.RAISED</code> or <code>BevelBorder.LOWERED</code>. With the three-argument constructor, you specify the highlight and shadow colors. With the five-argument constructor, you specify the outer highlight, inner highlight, outer shadow, and inner shadow colors, in that order.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createEmptyBorder()">Border createEmptyBorder()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createEmptyBorder(int, int, int, int)">Border createEmptyBorder(int, int, int, int)</a></td><td>Create an invisible border. If you specify no arguments, then the border takes no space, which is useful when creating a titled border with no visible boundary. The optional arguments specify the number of pixels that the border occupies at the top, left, bottom, and right (in that order) of whatever component uses it. This method is useful for putting empty space around your components.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createMatteBorder(int, int, int, int, java.awt.Color)">MatteBorder createMatteBorder(int, int, int, int, Color)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createMatteBorder(int, int, int, int, javax.swing.Icon)">MatteBorder createMatteBorder(int, int, int, int, Icon)</a></td><td>Create a matte border. The integer arguments specify the number of pixels that the border occupies at the top, left, bottom, and right (in that order) of whatever component uses it. The color argument specifies the color which with the border should fill its area. The icon argument specifies the icon which with the border should tile its area.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createTitledBorder(java.lang.String)">TitledBorder createTitledBorder(String)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createTitledBorder(javax.swing.border.Border)">TitledBorder createTitledBorder(Border)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createTitledBorder(javax.swing.border.Border, java.lang.String)">TitledBorder createTitledBorder(Border, String)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createTitledBorder(javax.swing.border.Border, java.lang.String, int, int)">TitledBorder createTitledBorder(Border, String, int, int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createTitledBorder(javax.swing.border.Border, java.lang.String, int, int, java.awt.Font)">TitledBorder createTitledBorder(Border, String, int, int, Font)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createTitledBorder(javax.swing.border.Border, java.lang.String, int, int, java.awt.Font, java.awt.Color)">TitledBorder createTitledBorder(Border, String, int, int, Font, Color)</a></td><td>Create a titled border. The string argument specifies the title to be displayed. The optional font and color arguments specify the font and color to be used for the title's text. The border argument specifies the border that should be displayed along with the title. If no border is specified, then a look-and-feel-specific default border is used. <p> By default, the title straddles the top of its companion border and is left-justified. The optional integer arguments specify the title's position and justification, in that order.<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/border/TitledBorder.html"><code>TitledBorder</code></a> defines these possible positions: <code>ABOVE_TOP</code>, <code>TOP</code> (the default), <code>BELOW_TOP</code>, <code>ABOVE_BOTTOM</code>, <code>BOTTOM</code>, and <code>BELOW_BOTTOM</code>. You can specify the justification as <code>LEADING</code> (the default), <code>CENTER</code>, or <code>TRAILING</code>. In locales with Western alphabets <code>LEADING</code> is equivalent to <code>LEFT</code> and <code>TRAILING</code> is equivalent to <code>RIGHT</code>.</td></tr><tr><td> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/BorderFactory.html#createCompoundBorder(javax.swing.border.Border, javax.swing.border.Border)">CompoundBorder createCompoundBorder(Border, Border)</a></td><td>Combine two borders into one. The first argument specifies the outer border; the second, the inner border.</td></tr></table><p><table border=1> <caption><a name="setgetapi">Setting or Getting a Component's Border</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#setBorder(javax.swing.border.Border)">void setBorder(Border)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#getBorder()">Border getBorder()</a></td><td>Set or get the border of the receiving <code>JComponent</code>.</td></tr><tr><td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/AbstractButton.html#setBorderPainted(boolean)">void setBorderPainted(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/AbstractButton.html#isBorderPainted()">boolean isBorderPainted()</a> <br> <em>(in <code>AbstractButton</code>, <code>JMenuBar</code>, <code>JPopupMenu</code>, <code>JProgressBar</code>, and <code>JToolBar</code>)</td><td>Set or get whether the border of the component should be displayed.</td></tr></table></blockquote><h3><a name="eg">Examples that Use Borders</a></h3><blockquote>Many examples in this lesson use borders.The following table lists a few interesting cases.<p><table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr><td> <a href="examples/index.html#BorderDemo"><code>BorderDemo</code></a></td><td> This section</td><td> Shows an example of each type of border that <code>BorderFactory</code> can create. Also uses an empty border to add breathing space between each pane and its contents.</td></tr><tr><td> <a href="../layout/examples/index.html#BoxAlignmentDemo"><code>BoxAlignmentDemo</code></a></td><td> <a href="../layout/box.html">How to Use BoxLayout</a></td><td> Uses titled borders.</td></tr><tr><td> <a href="../layout/examples/index.html#BoxLayoutDemo"><code>BoxLayoutDemo</code></a></td><td> <a href="../layout/box.html">How to Use BoxLayout</a></td><td> Uses a red line to show where the edge of a container is, so that you can see how the extra space in a box layout is distributed.</td></tr><tr><td> <a href="../components/examples/index.html#ComboBoxDemo2"><code>ComboBoxDemo2</code></a></td><td> <a href="../components/combobox.html">How to Use Combo Boxes</a></td><td> Uses a compound border to combine a line border with an empty border. The empty border provides space between the line and the component's innards.</td></tr></table> </blockquote> <div class=NavBit> <a target=_top href=icon.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=problems.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 Icons <br><b>Next page:</b> Solving Common Component Problems </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -