I want to remove the awkward blue border which I cannot remove by doing myTabbedPane.setBorder(null);
. What is a way of doing that?
This is the blue border I am talking about:
As I am new to the swing java library, I would also like to know how all the properties of components are changed if there is no method/it doesn't work. I heard there is something called UIManager but I can't find useful information about it.
The only thing I tried was calling setBorder property and calling null on it.
These properties are defined by the Look & Feel you are using (e.g. Windows L&F or Metal L&F).
You can change these properties globally (i.e. this applies to all JTabbedPanes you are using). The following code works for the Windows L&F and the Motiv L&F (you need to check for other L&F implementations):
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Insets;
public class Main extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Main());
}
public Main() {
this.setLayout(new BorderLayout());
JTabbedPane pane = new JTabbedPane();
pane.addTab("A", new JPanel());
pane.addTab("B", new JPanel());
pane.addTab("C", new JPanel());
Insets insets = UIManager.getInsets("TabbedPane.contentBorderInsets");
insets.top = -1;
insets.bottom = -1;
insets.left = -1;
insets.right = -1;
UIManager.put("TabbedPane.contentBorderInsets", insets);
this.add(pane, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800, 600);
this.setVisible(true);
}
}