Solved

Creating a border round a panel

Posted on 1998-10-27
4
822 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 46
Configure a Bean in an XML file 4 33
Chrome and Firefox Java 5 34
Html Table Looping (part 2) 5 11
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

831 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