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.
Related
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)));
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
I have designed a code for JTextPane, what I want to do is put that JTextPane in the bottom right corner, it is is fine as long as the form isn't resized (I want the form to be resizeable) but when it is resized the JTextPane does not move along. How can I make it stick to that right corner and move about if the form has been resized, I do not need it to cover the full contentPane. here is my code for the JTextPane
JTextPane txtpnHello = new JTextPane();
txtpnHello.setText("Hello");
txtpnHello.setEnabled(false);
contentPane.add(txtpnHello);
Thanks.
You can use a SpringLayout Manager, perhaps like this -
SpringLayout layout = new SpringLayout();
JPanel contentPane = new JPanel(layout); // <-- Add the layout manager.
JTextPane txtpnHello = new JTextPane();
// The "Spring" for right
layout.putConstraint(SpringLayout.EAST, txtpnHello, 5,
SpringLayout.EAST, contentPane);
// The "spring" for the bottom.
layout.putConstraint(SpringLayout.SOUTH, txtpnHello, 5,
SpringLayout.SOUTH, contentPane);
txtpnHello.setText("Hello");
txtpnHello.setEnabled(false);
contentPane.add(txtpnHello);
I want to design a GUI with theme of Black, but my etched border looks raised etched type.
I want to make it look lowered etched type. I can't find the color combination to do that. How would I do that?
It's looking like this, but the difference is that the background is Black.
Have you tried using a BevelBorder instead?
JPanel outerPanel = new JPanel();
outerPanel.setBackground(Color.black);
outerPanel.setPreferredSize(new Dimension(400, 400));
outerPanel.setLayout(new BorderLayout());
Border outsideBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
Border insideBorder = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
Border innerPanelBorder = BorderFactory.createCompoundBorder(outsideBorder , insideBorder );
JPanel innerPanel = new JPanel();
innerPanel.setBorder(innerPanelBorder);
innerPanel.setOpaque(false);
outerPanel.add(innerPanel);
As the title says, I am simply trying to set the margins (provide some padding) on a TextArea with a LineBorder set. Without setting the Border, .setMargins works fine. Here is the specific chunk of code.
aboutArea = new JTextArea("program info etc.....");
Border border = BorderFactory.createLineBorder(Color.BLACK);
aboutArea.setSize(400, 200);
aboutArea.setBorder(border);
aboutArea.setEditable(false);
aboutArea.setFont(new Font("Verdana", Font.BOLD, 12));
add(aboutArea);
I have tried each of these:
aboutArea.setMargins(10,10,10,10);
.getBorders(aboutArea).set(10,10,10,10);
UIManager.put("aboutArea.margin", new Insets(10, 10, 10, 10));
but nothing affects the margins after I apply the border, the padding is always 0. Any ideas how to set the padding on the textArea with the border?
What if you try adding a CompoundBorder , won't this do, this will give you almost same thing
JTextArea tarea = new JTextArea("program info etc.");
Border border = BorderFactory.createLineBorder(Color.BLACK);
tarea.setBorder(BorderFactory.createCompoundBorder(border,
BorderFactory.createEmptyBorder(10, 10, 10, 10)));