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

📄 guiutilities.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    //------------------------------------------------------------------    public static Point getComponentLocation( Component component )    {        return getComponentLocation( component, (Rectangle)null );    }    //------------------------------------------------------------------    public static void setAllEnabled( Component component,                                      boolean   enable )    {        if ( component instanceof Container )        {            for ( Component child : ((Container)component).getComponents( ) )                setAllEnabled( child, enable );        }        component.setEnabled( enable );    }    //------------------------------------------------------------------    public static void setHorizontalMargins( JTextComponent component,                                             int            margin )    {        Insets margins = component.getMargin( );        margins.left = Math.max( margin, margins.left );        margins.right = Math.max( margin, margins.right );        component.setMargin( margins );    }    //------------------------------------------------------------------    public static void setFocus( JComponent component )    {        if ( component.requestFocusInWindow( ) )        {            if ( component instanceof AbstractSpinner )                component = ((AbstractSpinner)component).getEditor( );            if ( component instanceof JTextComponent )            {                JTextComponent textComponent = (JTextComponent)component;                textComponent.setCaretPosition( textComponent.getText( ).length( ) );            }        }    }    //------------------------------------------------------------------    public static Font getFont( String name )    {        Font font = null;        try        {            Class<?> cls = Class.forName( CLASS_NAME_APP_FONT );            if ( cls.isEnum( ) )            {                for ( Object obj : cls.getEnumConstants( ) )                {                    if ( ((Enum)obj).name( ).equals( name ) )                        font = (Font)cls.getMethod( METHOD_NAME_GET_FONT ).invoke( obj );                }            }        }        catch ( Exception e )        {            e.printStackTrace( );        }        return font;    }    //------------------------------------------------------------------    public static void setFont( String    name,                                Component component )    {        try        {            Class<?> cls = Class.forName( CLASS_NAME_APP_FONT );            if ( cls.isEnum( ) )            {                for ( Object obj : cls.getEnumConstants( ) )                {                    if ( ((Enum)obj).name( ).equals( name ) )                    {                        cls.getMethod( METHOD_NAME_SET_FONT, Component.class ).invoke( obj, component );                        break;                    }                }            }        }        catch ( Exception e )        {            e.printStackTrace( );        }    }    //------------------------------------------------------------------    public static Box.Filler createFiller( )    {        return createFiller( 1, 1 );    }    //------------------------------------------------------------------    public static Box.Filler createFiller( int width,                                           int height )    {        Dimension size = new Dimension( width, height );        return new Box.Filler( size, size, size );    }    //------------------------------------------------------------------    public static Color scaleColourBrightness( Color colour,                                               float factor )    {        float[] hsbValues = new float[3];        Color.RGBtoHSB( colour.getRed( ), colour.getGreen( ), colour.getBlue( ), hsbValues );        return Color.getHSBColor( hsbValues[0], hsbValues[1],                                  Math.min( Math.max( 0.0f, hsbValues[2] * factor ), 1.0f ) );    }    //------------------------------------------------------------------    public static void setPaddedLineBorder( JComponent component )    {        setPaddedLineBorder( component, DEFAULT_BORDER_PADDING, DEFAULT_BORDER_PADDING,                             DEFAULT_BORDER_PADDING, DEFAULT_BORDER_PADDING );    }    //------------------------------------------------------------------    public static void setPaddedLineBorder( JComponent component,                                            int        padding )    {        setPaddedLineBorder( component, padding, padding, padding, padding );    }    //------------------------------------------------------------------    public static void setPaddedLineBorder( JComponent component,                                            int        vertical,                                            int        horizontal )    {        setPaddedLineBorder( component, vertical, horizontal, vertical, horizontal );    }    //------------------------------------------------------------------    public static void setPaddedLineBorder( JComponent component,                                            int        top,                                            int        left,                                            int        bottom,                                            int        right )    {        component.setBorder( BorderFactory.createCompoundBorder(                                            BorderFactory.createLineBorder( LINE_BORDER_COLOUR ),                                            BorderFactory.createEmptyBorder( top, left, bottom, right ) ) );    }    //------------------------------------------------------------------    public static void setPaddedRaisedBevelBorder( JComponent component )    {        setPaddedRaisedBevelBorder( component, DEFAULT_BORDER_PADDING, DEFAULT_BORDER_PADDING,                                    DEFAULT_BORDER_PADDING, DEFAULT_BORDER_PADDING );    }    //------------------------------------------------------------------    public static void setPaddedRaisedBevelBorder( JComponent component,                                                   int        padding )    {        setPaddedRaisedBevelBorder( component, padding, padding, padding, padding );    }    //------------------------------------------------------------------    public static void setPaddedRaisedBevelBorder( JComponent component,                                                   int        vertical,                                                   int        horizontal )    {        setPaddedRaisedBevelBorder( component, vertical, horizontal, vertical, horizontal );    }    //------------------------------------------------------------------    public static void setPaddedRaisedBevelBorder( JComponent component,                                                   int        top,                                                   int        left,                                                   int        bottom,                                                   int        right )    {        component.setBorder( BorderFactory.createCompoundBorder(                                            BorderFactory.createRaisedBevelBorder( ),                                            BorderFactory.createEmptyBorder( top, left, bottom, right ) ) );    }    //------------------------------------------------------------------}//----------------------------------------------------------------------

⌨️ 快捷键说明

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