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

📄 e748. moving the label!icon pair in a jbutton component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
When the size of the button component is larger than its contents, the label and icon are always kept together. In fact, the gap size (see e749 Setting the Gap Size Between the Label and Icon in a JButton Component) determines the fixed distance between them. Using two alignment methods, you can place the label/icon pair in one of nine possible locations. 
    // To create a button with an icon, see e746 Adding an Icon to a JButton Component
    
    // Place the contents in the nw corner
    button.setVerticalAlignment(SwingConstants.TOP);
    button.setHorizontalAlignment(SwingConstants.LEFT);
    
    // Place the contents centered at the top
    button.setVerticalAlignment(SwingConstants.TOP);
    button.setHorizontalAlignment(SwingConstants.CENTER);
    
    // Place the contents in the ne corner
    button.setVerticalAlignment(SwingConstants.BOTTOM);
    button.setHorizontalAlignment(SwingConstants.RIGHT);
    
    // Place the contents in the sw corner
    button.setVerticalAlignment(SwingConstants.BOTTOM);
    button.setHorizontalAlignment(SwingConstants.LEFT);
    
    // Place the contents centered at the bottom
    button.setVerticalAlignment(SwingConstants.BOTTOM);
    button.setHorizontalAlignment(SwingConstants.CENTER);
    
    // Place the contents in the se corner
    button.setVerticalAlignment(SwingConstants.BOTTOM);
    button.setHorizontalAlignment(SwingConstants.RIGHT);
    
    // Place the contents vertically centered on the left
    button.setVerticalAlignment(SwingConstants.CENTER);
    button.setHorizontalAlignment(SwingConstants.LEFT);
    
    // Place the contents directly in the center
    button.setVerticalAlignment(SwingConstants.CENTER);
    button.setHorizontalAlignment(SwingConstants.CENTER);
    
    // Place the contents vertically centered on the right
    button.setVerticalAlignment(SwingConstants.CENTER);
    button.setHorizontalAlignment(SwingConstants.RIGHT);
    

 Related Examples 

⌨️ 快捷键说明

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