0

The title may not be suitable, but here's the complete explanation

What I need is that my frame should have 3 buttons (Minimize, Maximize, Close) but the border of the frame should be customized (some color/gradient).

See this: Preview
(source: getintopc.com)

Edit : I have not started coding, because I have no idea where to start from

Community
  • 1
  • 1
Gagan93
  • 1,826
  • 2
  • 25
  • 38
  • 4
    You probably want to create your own complete look and feel. There's no one real answer to this question. Take a look at [**How to Write a Custom Look and Feel**](https://today.java.net/pub/a/today/2006/09/12/how-to-write-custom-look-and-feel.html) – Paul Samsotha Dec 25 '13 at 09:41
  • 3
    If you want to customize the frame, then you would draw it yourself. As you draw the whole frame, you can draw as many buttons as you want but you'll have to handle the events. By the way, you can change _Look and Feel_ on a single component, JFrame. – Alexey Ivanov Dec 25 '13 at 10:22
  • @alexey : you are right, i just want to modify exactly the outer border of JFrame, will you suggest some way to do it ? – Gagan93 Dec 25 '13 at 12:04

2 Answers2

2

Add the desired internal frame icons, seen here, to a container in an undecorated frame, illustrated here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

Some Look and Feels support JFrame decorations, for example the standard one, Metal, does:

Frame with LaF decorated border

You can check whether the LaF supports decorations or not by using LookAndFeel.getSupportsWindowDecorations().

By modifying the LaF you can change how frame decorations are painted.

Alternatively, you can create a frame without decorations at all. Call setUndecorated(true) on a frame instance:

Frame without decorations

So you can easily paint whatever you want in the content pane. Yet such window cannot be easily moved, resized, minimized or maximized unless you implement these features yourself.

You can find interesting the article Windows Java tip: How to control window decorations.


I used the following AFrame class:

public class AFrame {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame.setDefaultLookAndFeelDecorated(true);
                JFrame frame = new JFrame("A Frame");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                frame.setSize(200, 100);
                frame.setLocationByPlatform(true);

                frame.setVisible(true);
            }
        });
    }

}

To create frame without border:

  • Remove line JFrame.setDefaultLookAndFeelDecorated(true);
  • Add line frame.setUndecorated(true);

Update: I found series of articles on how add frame decorations to Nimbus Look and Feel:

The frame from the 3rd step looks this way:
Nimbus Look and Feel frame decorations: 3rd step rendering http://weblogs.java.net/sites/default/files/ThirdStep.png

You can use the code in these articles as the base to implement your own frame decorations.

Community
  • 1
  • 1
Alexey Ivanov
  • 11,541
  • 4
  • 39
  • 68