Set a gap between the beginning of the JLabel and the icon - java

I have a Java Swing form and JLabel like this:
What I need to do is inserting a gap in the beginning of the JLabel:
So it will not stuck to the border line.
Note 1 : I already used jLabName.setIconTextGap(35); but it did the below:
I need to insert the gap before the icon not after it!
Note 2 : The Border Setting And Type And other setting:

You can use compound borders for that.
For Example.
//get border of your component which is button as you say
Border border = myButton.getBorder();
//create a new empty border with name it margin
Border margin = new EmptyBorder(0,10,0,0); //top 0, left 10 , bottom 0, right 0
//now set compound border to your button(component), with margin
myButton.setBorder(new CompoundBorder(border, margin));
//NOTE: CompoundBorder accepts two borders as arguments, first one is inner border and last one is outer border

Fixed it with the following code:
a1.setBorder(new CompoundBorder(new EtchedBorder(), BorderFactory.createEmptyBorder(1, 8, 1, 1)));

Related

How to change border width of JTextarea in java

How to change the border width? I want a lighter border.
Below is my try
// Set border
Border border = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
textarea.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(5, 5, 5, 5)));
The LineBorder of the text area is 1 pixel wide.
The JScrollPane also has a LineBorder 1 pixel wide.
Don't add the LineBorder to the textarea. Just use the EmptyBorder.

Java Swing - JButton wrong border

I try to set new red border to my "Ok" button, but instead of I get from this. How to make 1-st picture? (it's photoshop)
I try
button.setBorder(new LineBorder(Color.RED, 1));
You overrided the button's default border. You should set a compound border using the existing one and a new red one.
Border innerBorder = button.getBorder();
Border outerBorder = new LineBorder(Color.RED, 1);
button.setBorder(new CompoundBorder(outerBorder, innerBorder));
Here is a one liner combined with using the BorderFactory :-)
button.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.RED, 1),
button.getBorder()));
Using BorderFactory - http://docs.oracle.com/javase/tutorial/uiswing/components/border.html#createapi

How to add margin of text in the JTextArea?

How can I add a Margin for text to the right and top like 5 pixel each inside the JTextArea.
Here is the Image: Click Here
public class SubTextField extends JTextArea{
public SubTextField()
{
setLineWrap(true);
setWrapStyleWord(true);
setPreferredSize(new Dimension(0,50));
Border b = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.black);
setBorder(b);
setFont(new Font("Arial",Font.PLAIN,16));
actionButtons();
}
}
setMargin(new Insets(5,0,0,5)); would create a margin of 5 pixels at the top and right.
(the parameters to the Insets object are top, left, bottom and right, respectively).
If you are using window builder then you can use the Layout Assistant support and set the insets and many other features like growing,filling easily.

Width of tabbed pane

How can I set a full width for a tabbed pane? I've tried working with the following code:
UIDefaults def = UIManager.getLookAndFeelDefaults();
def.put( "TabbedPane.tabInsets", new Insets(0, 0, 0, 250) );
But, it doesn't seem to increase the size fully, whatever I work with. It either creates two rows, or isn't full length.
Picture to understand the problem:
http://s8.postimage.org/lr47nm9tx/tabbedpanefull.png

swing: creating thin button borders that look the same as the look&feel default

I have an icon button that I want to use with a border. The default border looks too thick.
What's the easiest way to create a border with the same colors as the current look + feel?
Button myButton = createMyIconButton();
...
public Button createMyIconButton()
{
...
setBorder(BorderFactory.createLineBorder(???, 1));
}
The default border looks too thick.
Maybe you are looking for:
button.setMargin( new Insets(2, 2, 2, 2) );

Categories