Solved

Creating a border round a panel

Posted on 1998-10-27
4
824 Views
Last Modified: 2009-07-29
IS this possible? I know under windows, there is a seperator line you can use to split a screen, and the same exists under X, is there a seperator I can use in java on theese platforms, or is there a simpler way to put a border round a panel?
0
Comment
Question by:nigel5
  • 2
4 Comments
 
LVL 5

Expert Comment

by:msmolyak
ID: 1226471
It is easy in Swing, each component has serBorder() method. There are no built-in borders in AWT, but you can certainly craw one yourself. I would recommend using Swing.
0
 

Author Comment

by:nigel5
ID: 1226472
Sorry, this question was submited twice because of a fault yesterday. The other question id is...
http://www.experts-exchange.com/Q.10092754
Anyway, I am not sure how to use swing on a sun platform, as I have only seen it on the PC, and I need to use both.
0
 

Author Comment

by:nigel5
ID: 1226473
This question will be deleted soon I hope. se question
http://www.experts-exchange.com/Q.10092754
0
 
LVL 4

Accepted Solution

by:
rembo earned 50 total points
ID: 1226474

Here's a BorderPanel class.  You can change the border size
to a parameter for more flexibility:

import java.awt.*;

class BorderPanel extends Panel
{
    Color color1 = Color.white;
    Color color2 = Color.black;
    int border = 5;

    BorderPanel()
    {
    }

    BorderPanel(int w)
    {
        border = w;
    }

    BorderPanel(int w, Color c1, Color c2)
    {
        border = w;
        color1 = c1; color2 = c2;
    }

    BorderPanel(Color c1, Color c2)
    {
        color1 = c1; color2 = c2;
    }

    public Insets insets()
    {
        return new Insets(border+2, border+2, border+2, border+2);
    }

    public void paint(Graphics g)
    {
        super.paint(g);

        int w = size().width-1, h = size().height-1;

        g.setColor(color1);

        for(int i=0; i<border; i++) {
            g.drawLine(i,i,w-i,i);
            g.drawLine(i,i,i,h-i);
        }

        g.setColor(color2);

        for(int i=0; i<border; i++) {
            g.drawLine(w-i,h-i, w-i,i);
            g.drawLine(w-i,h-i, i,h-i);
        }
    }
}

Hope that helps...

-Tony

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 82
hibernate example using maven 12 75
mysql jsp example issue 32 67
Eclipse with various Java releases 7 42
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question