Look and Feel Is Not Updating in Swing Jtabbedpane

Java Panel not updating completely occasionally

Since I am not able to see the code this answer is more from what you could try to do with the information I have :)

  1. Updating a JPanel is tricky if not done from the EDT. Even when done from the EDT I have had issue when trying to change the entire structure of the JPanel and repainting it. Instead in these places I have changed to using a JTabbedpane. Drop a tab and recreate it. Much more easier to do. I am not sure if that will help in this case.
  2. Next the layout. Are you using any Layout manager? If you have absolutely positioned stuff, then depending on the monitors size and resolution all things will go haywire. I would recommend using the JGoodies - Forms layout. Link here - http://www.jgoodies.com/freeware/forms/

Sorry couldnt be more of help.. :(

Java look and feel JTabbedPane

The JTabbedPane is created before the PLAF is set. There are at least two fixes.

  1. Move the line that creates the tabbed pane into the main, and put it after the call to set the PLAF.
  2. Call SwingUtilities.updateComponentTreeUI(topLevelContainer) as shown in the Nested Layout Example. That example allows the PLAF to be changed by the user at run-time.

Tab in JTabbedPane does not reflect changes on button press

You may be looking for the setTitleAt() method.

Addendum: For comparison, here's an sscce that allows multiple edits.

TabEdit

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

/**
* @see http://stackoverflow.com/a/11007109/230513
*/
public class TabEdit extends JPanel {

private static final int MAX = 5;
private static final String NAME = "Tab ";
private final JTabbedPane pane = new JTabbedPane();

public TabEdit() {
for (int i = 0; i < MAX; i++) {
pane.add(NAME + String.valueOf(i), new TabContent(i));
}
this.add(pane);
}

private class TabContent extends JPanel {

private TabContent(final int i) {
final JTextField jtf = new JTextField(
"Please edit the name of " + NAME + String.valueOf(i));
this.add(jtf);
jtf.addActionListener(new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
pane.setTitleAt(i, jtf.getText());
}
});
}

@Override
public Dimension getPreferredSize() {
return new Dimension(320, 120);
}
}

private void display() {
JFrame f = new JFrame("TabEdit");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {

@Override
public void run() {
new TabEdit().display();
}
});
}
}

How to change tabs location in JTabbedPane?

As you already pointed out, you have to use an LookAndFeel which supports this design (centered Tab-Button).

When your selected LaF does not support this, you have to write your own TabbedPaneUI.
(But this may not be very easy.)

If you do not want to create your own TabbedPaneUI, you have to look for an existing custom TabbedPaneUI or TabbedPane-Component, which support this kind of layout.

You can take a look at this article, to get started:

http://www.javaworld.com/article/2072927/swing-gui-programmingloseandmaxtabbedpane--an-enha/swing-gui-programming/closeandmaxtabbedpane--an-enhanced-jtabbedpane.html

JToolBars in JTabbedPanes; incorrect tab name when docked and undocked

The solution was to use a ContainerListener to detect a component added through the implemented componentAdded method. When a component was added to the JTabbedPane, I called a method to update the tab names with the components name, set via .setName().

public void componentAdded(ContainerEvent added) {
updateTabs();
}

public void updateTabs() {
for (int i = 0; i < tabbedPane.getComponents().length; i++) {
tabbedPane.setTitleAt(i,
tabbedPane.getComponents()[i].getName());
}
}


Related Topics



Leave a reply



Submit