Solved

Creating a border round a panel

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eclipse Neon and jdk 1.8.0 11 126
advertisement module in core php 4 144
more than one jdk and one jre 1 30
expectj telnet failing 5 19
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now