Confused with BorderFactory class
Hi All,
I just started to learn advanced java programming. Some of the concept of this programming seems quit confusing. And BorderFactory class is one it. I don't have any idea about the methods and constructors of BorderFactory class of java. If you posses sound knowledge about the BorderFactory class then please try to share it with me. Your any help over BorderFactory class would be greatly appreciated.
Re: Confused with BorderFactory class
Every BorderFactory class component can have one or more borders. Borders are incredibly useful objects that, while not themselves components, know how to draw the edges of Swing components. Borders are useful not only for drawing lines and fancy edges, but also for providing titles and empty space around components. To put a border around a JComponent, you use its setBorder method. You can use the BorderFactory class to create most of the borders that Swing provides.
Re: Confused with BorderFactory class
Hi,
I suggest you to study following example of BorderFactory class, which will definitely solve your confusion about it:
Code:
import javax.swing.BorderFactory;
public class BorderFactoryMain extends JFrame {
public MainClass(String name) {
getContentPane().setLayout(new FlowLayout());
JLabel labelTwo = new JLabel("www.java2s.com");
labelTwo.setBorder(BorderFactory.createEtchedBorder());
add(labelTwo);
JLabel labelThree01 = new JLabel("MatteBorder");
labelThree01.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink));
add(labelThree01);
JLabel labelSix1 = new JLabel("CompoundBorder");
Border one = BorderFactory.createEtchedBorder();
Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue);
labelSix1.setBorder(BorderFactory.createCompoundBorder(one, two));
add(labelSix1);
}
public static void main(String[] ardgs) {
JFrame frame1 = new MainClass("javax.swing.JButton");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.pack();
frame1.setVisible(true);
}
}
Re: Confused with BorderFactory class
Below I have give few methods of BorderFactory class along with it's different parameters:
- createTitledBorder(String ttl)
- createTitledBorder(Border bdr, String ttl, int ttlJustification, int ttlPosition, Font ttlFont, Color ttlColor)
- createTitledBorder(Border bdr, String ttl, int ttlJustification, int ttlPosition, Font ttlFont)
- createTitledBorder(Border bdr, String ttl, int ttlJustification, int ttlPosition)
- createTitledBorder(Border bdr, String ttl)
Re: Confused with BorderFactory class
Hi friend,
I hope something below code can help you to know about the BorderFactory class:
Code:
import javax.swing.JFrame;
import javax.swing.border.Border;
import javax.swing.JButton;
public class BorderFactoryDM
{
public static void main(String[] arf) {
JFrame FND = new JFrame("Empty Borders");
FND.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Border emptyBorder1 = BorderFactory.createEmptyBorder(20, 20, 0, 0);
JButton emptyButton1 = new JButton("With Empty");
emptyButton1.setBorder(emptyBorder1);
JButton nonemptyButton1 = new JButton("Without Empty");
Container contentPane1 = FND.getContentPane();
contentPane1.add(emptyButton1, BorderLayout.NORTH);
contentPane1.add(nonemptyButton1, BorderLayout.SOUTH);
FND.pack();
FND.setSize(400, FND.getHeight());
FND.setVisible(true);
}
}
Re: Confused with BorderFactory class
Hello friend,
A BorderFactory class is nothing but the 'Factory class' which is used for the for Border object vending. The BorderFactory class of java is taken form the java package known as 'java.lang.Object'. This java class extends 'Object' interface of java. The 'createMatteBorder' method of BorderFactory class is used for the creations of 'matte-look border' and which comprises many specified icon tiles.