Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating a border round a panel

Posted on 1998-10-27
4
Medium Priority
?
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
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 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 step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

610 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