5 Replies Latest reply: Dec 19, 2011 10:43 AM by mKorbel RSS

    How to customize the title bar on my own Look And Feel?

      Hi all!

      I am creating my own Look and Feel which extends from NimbusLookAndFeel. What I'm doing is overwriting UIDefaults values??, referring to the Painters. For example:

      +uiDefault.put ("Button [Enabled]", new ButtonEnabledPainter());+

      But now I need is to customize the title bar of the JFrame's, but I do not see this option in Painter's values ??can be overwritten by Nimbus (http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults . html).

      You know as possible? I have to overwrite an existing UI component? The idea is I want to make the look and feel like SeaGlass, but the code seems a bit complex to know where to begin.

      I hope you can guide me on this issue.

      Thank you very much for everything! And excuse my English!.

        • 1. Re: How to customize the title bar on my own Look And Feel?
          But now I need is to customize the title bar of the JFrame's,
          1) J/Frame and J/Dialog came from Native OS, and always has same Colors schema as another Containers, you can change that by changing Color's theme in Native OS

          2) you re able to create JPanel with f.e. GradientPaint and put there JButton with Icon, there is simple to override methods from WindowListener/WindowAdapter

          3) SeaGlass is most complex Custom L&F, then I suggest ---> please to check aephyr code source http://aephyr.googlecode.com/svn/trunk/nimbusthemecreator/aephyr/swing/nimbus/


          4) I forgot that is possible to change TitleBar for Windows OS and by apply SystemLookAndFeel
          • 2. Re: How to customize the title bar on my own Look And Feel?
            MKorbel Hello, thanks for the answer!

            But I've seen you could customize the title pane of the JFrame and JPanel regardless of operating system. For example, the application JDownloader, use the Substance LAF, and it has custom title pane. the thing is I do not know how this can be done.

            • 3. Re: How to customize the title bar on my own Look And Feel?
              right, Substance LAF, and another L&F's put there own and Customized JPanel with JButtons.

              put directly to the Container one JPanel with proper Borders that simulating your idea or Container that came from Native OS

              all containers for Java6 has implemented BorderLayout, then only myContainer.add(fatherPanel)

              to this "fatherPanel" with BorderLayout, put another two JPanels one to the CENTER

              2nd. to the NORTH (or JLabel or JComponent) with JButton(s) that contains Icon and override WindowListener/WindowAdapter/WindowState for this/these JButton(s)
              • 4. Re: How to customize the title bar on my own Look And Feel?
                I don't quite understand what you mean. It is possible to explain it to me with more details?

                Sorry for my English!

                Thank you very much!
                • 5. Re: How to customize the title bar on my own Look And Feel?
                  very simple example, with direct methods
                  import java.awt.*;
                  import java.awt.event.*;
                  import java.util.LinkedList;
                  import java.util.Queue;
                  import javax.swing.*;
                  public class NimbusBorderPainterDemo extends JFrame {
                      private static final long serialVersionUID = 1L;
                      private JFrame frame = new JFrame();
                      private JPanel fatherPanel = new JPanel();
                      private JPanel contentPanel = new JPanel();
                      private GradientPanel titlePanel = new GradientPanel(Color.BLACK);
                      private JLabel buttonPanel = new JLabel();
                      private Queue<Icon> iconQueue = new LinkedList<Icon>();
                      public NimbusBorderPainterDemo() {
                          JButton button0 = createButton();
                          button0.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                          JButton button1 = createButton();
                          button1.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                  frame.setExtendedState(MAXIMIZED_BOTH | NORMAL);
                              }//quick implemented, not correct you have to override both methods
                          JButton button2 = createButton();
                          button2.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                  int confirm = JOptionPane.showOptionDialog(frame,
                                          "Are You Sure to Close Application?", "Exit Confirmation",
                                          JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                                          null, null, null);
                                  if (confirm == JOptionPane.YES_OPTION) {
                          buttonPanel.setLayout(new GridLayout(0, 3, 5, 0));
                          buttonPanel.setPreferredSize(new Dimension(160, 30));
                          buttonPanel.add(button0);// JLabel is best and cross_platform JComponents
                          buttonPanel.add(button1);// not possible put there witouth set Dimmnesion
                          buttonPanel.add(button2);// and LayoutManager, work in all cases better
                          titlePanel.setLayout(new BorderLayout());//than JPanel or JCompoenent
                          titlePanel.add(new JLabel(nextIcon()), BorderLayout.WEST);
                          titlePanel.add(new JLabel("My Frame"), BorderLayout.CENTER);
                          titlePanel.add(buttonPanel, BorderLayout.EAST);
                          JTextField field = new JTextField(50);
                          JButton btn = new JButton("Close Me");
                          btn.addActionListener(new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                          fatherPanel.setLayout(new BorderLayout());
                          fatherPanel.add(titlePanel, BorderLayout.NORTH);
                          fatherPanel.add(contentPanel, BorderLayout.CENTER);
                          frame.setLocation(50, 50);
                          ComponentMover cm = new ComponentMover(frame, titlePanel);
                          //by camickr http://tips4java.wordpress.com/2009/06/14/moving-windows/
                      private JButton createButton() {
                          JButton button = new JButton();
                          button.setMargin(new Insets(0, 0, 0, 0));
                          return button;
                      private Icon nextIcon() {
                          Icon icon = iconQueue.peek();
                          return icon;
                      private class GradientPanel extends JPanel {
                          private static final long serialVersionUID = 1L;
                          public GradientPanel(Color background) {
                          public void paintComponent(Graphics g) {
                              if (isOpaque()) {
                                  Color background = new Color(168, 210, 241);
                                  Color controlColor = new Color(230, 240, 230);
                                  int width = getWidth();
                                  int height = getHeight();
                                  Graphics2D g2 = (Graphics2D) g;
                                  Paint oldPaint = g2.getPaint();
                                  g2.setPaint(new GradientPaint(0, 0, background, width, 0, controlColor));
                                  g2.fillRect(0, 0, width, height);
                      public static void main(String[] args) {
                          SwingUtilities.invokeLater(new Runnable() {
                              public void run() {
                                  try {
                                  } catch (Exception fail) {
                                  UIManager.getLookAndFeelDefaults().put("nimbusFocus", Color.RED);
                                  NimbusBorderPainterDemo nimbusBorderPainterDemo = new NimbusBorderPainterDemo();