0

I use jgoodies in my project. It works good only with some components.

Look at my project, please.

enter image description here

As you can see JButton, JTextField, JLabel, JFrame have been successfully modified. But JTabbedPane and JRadioButton have not been modified. Jgoodies had no impact on them. JTabbedPane created when the user selects the menu item. You can see it in this code:

item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            createTabbedPane();
            fieldForName.requestFocus();
        }

    });

In this ActionListener I call method createTabbedPane(); that creates JTabbedPane:

private static void createTabbedPane() {
    taskTabbedPane.setBounds(50, 50, 1000, 550);
    taskTabbedPane.addTab("Задача", createTasksMainInfoPanel());
    taskTabbedPane.addTab("Данные", null);
    taskTabbedPane.setEnabledAt(1, false);
}

I set look and fell in main method:

public static void main(String[] args) {
    // TODO Auto-generated method stub
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            } catch (UnsupportedLookAndFeelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            createAndShowGui();
        }
    });

}

What I'm doing wrong?

  • 2
    Just some sort of graphic of some fields and labels doesn't really tell us anything. Please edit your question to include the minimal amount of code to demonstrate the problem, and exactly what it's doing or not doing vs. what you want it to do. – blm Nov 13 '15 at 08:08
  • 1
    @blm *"..minimal amount of code to demonstrate the problem"* AKA a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Nov 13 '15 at 08:20
  • The PlastcLookAndFeel has different tab style see PlasticLookAndFeel#setTabStyle(String), you can use default, embedded, Metal – Petter Friberg Nov 13 '15 at 09:01
  • @PetterFriberg, I added Plastic3DLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE); before UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); and nothing changed. Help me please. Maybe I should add Plastic3DLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE); to different location? – Александр Елизаров Nov 13 '15 at 09:23
  • I'm not familiare to jgoodis style, you are sure that the tabs should not look like this in TAB_STYLE_METAL_VALUE.., try to improve your question with excpected result and your current modification, – Petter Friberg Nov 13 '15 at 09:30
  • Why do you have javax.swing.SwingUtilities.invokeLater(new Runnable() in the main?, do you have another swing application already running?, or is this some convention that I'm not used to.... – Petter Friberg Nov 13 '15 at 09:32
  • As far as I know the invokeLater "should be used when an application thread needs to update the GUI.", but you have not started it yet??, or have you? – Petter Friberg Nov 13 '15 at 09:35
  • @PetterFriberg, I don't know what to do. I tried everything but JTabbedPane has not changed. I try to debug it. I add this code: System.out.println(PlasticLookAndFeel.getTabStyle()); before PlasticLookAndFeel.setTabStyle(PlasticLookAndFeel.TAB_STYLE_METAL_VALUE); and after that. In the first case it prints "default" in second case it prints "metal". So, we can see that tab style changed. but it does not affect the appearance of the JTabbedPane – Александр Елизаров Nov 13 '15 at 09:45
  • Invoke `setLookAndFeel()` _before_ `invokeLater()`. – trashgod Nov 13 '15 at 11:42
  • or just remove it.... – Petter Friberg Nov 13 '15 at 12:10
  • @trashgod there is not the change, I think than JGoodies should be initialized on Event Dispatch Thread as rest of the L&Fs, no idea whats happens without an SSCCE / MCVE, but in Win10 works (OPs idea to add JTabbedPane at runtime) for me in Java6 , 7 and 8 too, by using lates (and free) jgoodies-common-1.8.1 and jgoodies-looks-2.7.0 – mKorbel Nov 13 '15 at 13:27
  • @mKorbel makes a good point; invoke `setLookAndFeel()` _before_ `setDefaultLookAndFeelDecorated()`, for [example](https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#example). – trashgod Nov 13 '15 at 17:31

2 Answers2

0

I decided my problem. I found 2 solutions. The first solution is to add this code:

taskTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

Another solution is to add this code:

SwingUtilities.updateComponentTreeUI(taskTabbedPane);

Thank you all for your help

0

It seems to me that the JTabbedPane is created before the JGoodies L&f is installed. That should explain why updating the component tree affects the JTabbedPane UI delegates. Your method #createTabbedPane does not create the JTabbedPane, it just configures it.

A change of the tab layout policy is not required. Updating the component tree is only necessary if you change the L&f at runtime.

Btw. all Swing initialization must happen in the EDT, and so it is necessary to create the GUI in the EDT.