?
Solved

Creating a border round a panel

Posted on 1998-10-27
4
Medium Priority
?
827 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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