Java Program to add Titled Border to Panel in Swing

Java 8Object Oriented ProgrammingProgramming

To set Titled Border to Panel, let us first create a Panel for our Java Swing Application:

JPanel panel = new Jpanel(new BorderLayout());

Now, set the titled border:

panel.setBorder(new TitledBorder("Displaying Titled Border"));

The following is an example to add Titled Border to Panel in Swing:

Example

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class SwingDemo {
   public static void main(String[] args) {
      JPanel panel = new JPanel(new BorderLayout());
      panel.setBorder(new TitledBorder("Displaying Titled Border"));
      panel.add(new JButton("Demo Button"), BorderLayout.SOUTH);
      JOptionPane.showMessageDialog(null, panel);
   }
}

Output

raja
Published on 03-May-2019 07:42:32
Advertisements