In this example we create a compound border, a border around border. Here, instead of creating a new instance of Border
class directly we create the border using the BorderFactory
factory class.
package org.kodejava.swing;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import java.awt.*;
public class CompoundBorderExample extends JFrame {
public CompoundBorderExample() {
initializeUI();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(
() -> new CompoundBorderExample().setVisible(true));
}
private void initializeUI() {
setSize(500, 500);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLayout(new FlowLayout(FlowLayout.LEFT));
BevelBorder raisedBevel =
(BevelBorder) BorderFactory.createBevelBorder(BevelBorder.RAISED);
BevelBorder loweredBevel =
(BevelBorder) BorderFactory.createBevelBorder(BevelBorder.LOWERED);
Border border = BorderFactory.createCompoundBorder(raisedBevel, loweredBevel);
JPanel panel = new JPanel();
panel.setBorder(border);
setContentPane(panel);
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024