⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttonpanel2.java

📁 CroftSoft Code Library是一个开源的可移植的纯Java游戏库
💻 JAVA
字号:
     package com.croftsoft.core.gui;

     import java.awt.*;
     import javax.swing.*;

     import com.croftsoft.core.lang.NullArgumentException;

     /*********************************************************************
     * A JPanel of JButtons evenly distributed in a single horizontal row.
     *
     * <p>
     * Uses GridBagLayout instead of GridLayout to ensure even distribution
     * during layout of the Buttons when the JPanel is odd-sized.
     * </p>
     *
     * <p>
     * Example:
     * <code>
     * <pre>
     * buttonPanel2 = new ButtonPanel2 (
     *   new JButton [ ] {
     *     playJButton  = new JButton ( "Play"  ),
     *     stopJButton  = new JButton ( "Stop"  ),
     *     pauseJButton = new JButton ( "Pause" ) } );
     * </pre>
     * </code>
     * </p>
     *
     * @version
     *   2001-07-10
     * @since
     *   2001-07-10
     * @author
     *   <a href="http://croftsoft.com/">David Wallace Croft</a>
     *********************************************************************/

     public final class  ButtonPanel2
       extends JPanel
     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
     {

     /*********************************************************************
     * @param  panelBackgroundColor
     *
     *   If null, the default will be used.
     *
     * @throws NullArgumentException
     *
     *   If jButtons is null or jButtons[i] is null.
     *********************************************************************/
     public  ButtonPanel2 (
       JButton [ ]  jButtons,
       Color        panelBackgroundColor )
     //////////////////////////////////////////////////////////////////////
     {
       super ( new GridBagLayout ( ) );

       NullArgumentException.check ( jButtons );

       GridBagConstraints  gridBagConstraints = new GridBagConstraints ( );

       gridBagConstraints.weightx = 1.0;

       gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;

       for ( int  i = 0; i < jButtons.length; i++ )
       {
         JButton  jButton = jButtons [ i ];

         NullArgumentException.check (
           jButton, "jButtons[" + i + "] is null" );

         gridBagConstraints.gridx = i;

         add ( jButton, gridBagConstraints );
       }

       if ( panelBackgroundColor != null )
       {
         setBackground ( panelBackgroundColor );
       }
     }

     /*********************************************************************
     * this ( jButtons, null );
     *********************************************************************/
     public  ButtonPanel2 ( JButton [ ]  jButtons )
     //////////////////////////////////////////////////////////////////////
     {
       this ( jButtons, null );
     }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -