Search code examples
javaswingjpanellook-and-feelseaglass

Customizing JPanel with Sea Glass Look and Feel


I have a JFrame and a JPanel. I have added my JPanel onto my JFrame. I am using Sea Glass Look and Feel. My JPanel has a title and a border created through the following code : panel.setBorder(BorderFactory.createTitledBorder("Titled Panel"));

The problem is when I run my program with Sea Glass Look and Feel, the border does not show; but when I disable it the border will show as I want it. Here is my code:

import com.seaglasslookandfeel.*;

public class SeaGlassLF extends JFrame {

    SeaGlassLF() {
    this.setPreferredSize(new java.awt.Dimension(300, 300));
    this.setSize(300, 300);
    this.setLayout(new java.awt.BorderLayout());
    this.setVisible(true);

    JPanel panel = new JPanel();
    panel.setPreferredSize(new java.awt.Dimension(200, 200));
    panel.add(new javax.swing.JButton("Click Me"));
    panel.setBorder(BorderFactory.createTitledBorder("Titled Panel"));

    this.add(panel, BorderLayout.CENTER);

}

public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                UIManager
                        .setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
            } catch (Exception e) {
                e.printStackTrace();
            }

            SeaGlassLF sg = new SeaGlassLF();

        }
    });
   }
  }

Qsn. What could be the cause and how do we solve this?

Below are the images showing the output of the program.

  1. With NO Sea Glass Look and Feel(Border available -pointed by the red arrow).

enter image description here

  1. With Sea Glass Look and Feel(no border available).

enter image description here


Solution

    • in Seaglas L&F is required to override possition for titlePossition, -

    • e.g. code line

    .

    panel.setBorder(BorderFactory.createTitledBorder(null, 
         "Titled Panel", TitledBorder.DEFAULT_JUSTIFICATION, 
         TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 12)));
    

    generated me (by using seaglasslookandfeel-0.1.7.3.jar) this

    .

    enter image description here