1

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

CN1002
  • 1,115
  • 3
  • 20
  • 40

2 Answers2

3
  • 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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

Well this is a pretty brute-force way:

UIManager.getDefaults().put("TitledBorder.border", BorderFactory.createLineBorder(Color.black));

But I'm sure (I hope!) there are more elegant solutions.

Every look and feel can set these values. I guess the authors of this look and feel have decided that lined borders don't fit with their style, so have hidden them.

David Lavender
  • 8,021
  • 3
  • 35
  • 55