Pages - GamesandApps

How To Create Borders In Java

Wan to to create BORDERS in Java?

You can add various kinds of borders to your Frame and even your objects used in Java Frames.
Here's a simple demonstration on how to use various borders on your Frame.

If you want to add any single of these Borders to your Frame, it should be simple. If you have done some Java programming you should be able to edit the code and take out an individual Border Style. If you can't, no problem, just ask me, i'll do it for you!

Here's the code, compile as

import java.awt.*;
import javax.swing.*;
import java.awt.event.* ;
import javax.swing.border.* ;

public class BorderTest extends JFrame //implements WindowListener
   JPanel p = new JPanel();
   Border[] border = new Border[] 

         BorderFactory.createTitledBorder("Border types"),
       BorderFactory.createMatteBorder(10, 10, 10, 10,,

    p.setLayout(new GridLayout(border.length, 0, 3, 3));

   for (int i = 0; i < border.length; i++) 
     JPanel borderPanel = new JPanel();
   getContentPane().add(p, "Center");
   setSize(600, 400);

addWindowListener(new WindowAdapter() 
     public void windowClosing(WindowEvent e) 

 public static void main(String[] args) 
   JFrame frame = new BorderTest();;



Here's a sample output of the program :-
how to create borders in java - output
Output of Border Test Program

No comments:

Post a Comment