Merge pull request #2312 from SiboVG/issue-2311
[#2311] Center text in component add button
This commit is contained in:
commit
936a37d1b9
@ -237,7 +237,6 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
|
|||||||
/**
|
/**
|
||||||
* Adds a buttons to the panel in a row. Assumes.
|
* Adds a buttons to the panel in a row. Assumes.
|
||||||
*
|
*
|
||||||
* @param label Label placed before the row
|
|
||||||
* @param row Row number
|
* @param row Row number
|
||||||
* @param b List of ComponentButtons to place on the row
|
* @param b List of ComponentButtons to place on the row
|
||||||
*/
|
*/
|
||||||
@ -318,20 +317,20 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
|
|||||||
public ComponentButton(String text, Icon enabled, Icon disabled) {
|
public ComponentButton(String text, Icon enabled, Icon disabled) {
|
||||||
super(text, enabled);
|
super(text, enabled);
|
||||||
|
|
||||||
setVerticalTextPosition(SwingConstants.BOTTOM); // this will put the text below the icon
|
setVerticalTextPosition(SwingConstants.BOTTOM); // Put the text below the icon
|
||||||
setHorizontalTextPosition(SwingConstants.CENTER); // this will center the text horizontally beneath the icon
|
setHorizontalTextPosition(SwingConstants.CENTER); // Center the text horizontally
|
||||||
//setIconTextGap(0); // this is optional, it sets the gap between the icon and the text
|
//setIconTextGap(0); // Optional; sets the gap between the icon and the text
|
||||||
|
|
||||||
// set the disabled icon if it is not null
|
// set the disabled icon if it is not null
|
||||||
if (disabled != null) {
|
if (disabled != null) {
|
||||||
setDisabledIcon(disabled);
|
setDisabledIcon(disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
setHorizontalAlignment(SwingConstants.CENTER); // this will center the button itself in its parent component
|
setHorizontalAlignment(SwingConstants.CENTER); // Center the button in its parent component
|
||||||
|
|
||||||
// if you have multiline text, you could use html to format it
|
// if you have multiline text, you could use html to format it
|
||||||
if (text != null && text.contains("\n")) {
|
if (text != null && text.contains("\n")) {
|
||||||
text = "<html>" + text.replace("\n", "<br>") + "</html>";
|
text = "<html><center>" + text.replace("\n", "<br>") + "</center></html>";
|
||||||
setText(text);
|
setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user