TabbedPane L&F changed
Hi, I have a GUI with TabbedPane the tabs of which were displayed in gray color with setOpaque property set to true. This is set for all UI container components to get a gray background overall. However, without any change to code (could be the upgrade to Java 6 that we did recently ?) , the tabs of TabbedPane have started showing a windows L&F when selected. they still show the gray when not selected. Can anyone help.
To get better help sooner, post a SSCCE that clearly demonstrates your problem.
Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
db
Similar Messages
-
Hi all,
I have stumbled on strange swing behavior on Windows, most probably connected to double buffering introduced in java 6.
Once in a while Windows stops redrawing my JFrame. From the java side everything seems ok - all the components are painted (that is, all native methods called), EventQueue normally processed by EDT, but repainted GUI is not shown on the screen. Note that OS has the repainted info - if I cover part of the application window with another window (e.g. explorer), and hid it back, the part that was covered is repainted. This happens even if I have java app halted on debug, so no other java actions can cause this repaint - OS has to have this image, it just does not put it on the screen. When I minimize/maximize the app, everything goes back to normal.
Note that I can normally operate the app "as if" it was painted - I can change tabs, click buttons (even though I can't see them), and results of these actions are painted by java to some offscreen buffer, but are only shown when I cover/uncover my app with another window, or min/max it. Min/Maxing ends this strange state and further repaints are shown normally.
Did any of you have this kind of problem? Any idea how to approach/resolve it or what can be the cause?
Java is 1.6.20, I have seen the behavior on Windows XP, Vista and 2008. It is not reproducible, it just happens sometimes. I haven't seen that on Java 5. Turning off double buffering resolves that, but is not feasible due to degraded user experience.
Thanks in advance for your help!
JakubThanks for your help so far, perhabs this is something with the driver, but I use fairly generic windows distribution.
EDT is not hosed, it is processing events normally (I checked that on debug step-by-step). We do not override any paint methods, and this is rather something on different level - it is not "a component not being repainted" it is "everything is repainted, but not shown on screen". Including tabbedPane's tab changes, menu display, etc. I can even see cursor changing into carret when I hover over "not shown" textfield.
Displaying and then disposing of modal dialog also fixes the state, as do resizing of the JFrame. -
DispatchEvent() problem (bug?)
Hi all.
I'm using a glasspane to process all mouse clicks that occur on inert, or 'no-state' components that don't require to be redrawn when they are clicked (ie
SwingUtilities.getDeepestComponentAt(contentPane, x, y)
returns a component such as a jpanel or a jlabel), and i'm redirecting all other events using:
MouseEvent event2 = SwingUtilities.convertMouseEvent(glassPane, event, component);component.dispatchEvent(event2);
The problem is that the dispatchEvent method doesn't trigger changes in the components' state or GUI that would normally occur if I wasn't using a glasspane: the checkmarks for checkboxes don't appear, comboboxes don't display their menus, textfields don't display a caret, buttons don't click, tabbedpanes don't change tabs, etc.
I've tried the using component.doClick() and it works fine, but i'm stumped for any component that doesn't extend AbstractButton. I don't feel like adding mouse listeners to all my components (there are over 100 of them!) just to call processMouseEvent (whether or not that would solve my problem) because they don't otherwise need to listen for mouse clicks (validations are processed when an action occurs on an OK button). Do I need to redirect the mouse events in a different way? Is there a command i should add after the dispatchEvent statment?
I could really use some help. Thanx :)Thanx viravan for your input. After trying it out, however, a few problems arose:
A) Without considering the fact that you're suggestion would lead to a bad archetacture, as you probably know ( ;o) ), that would require that I add a mouse listener to all components just to make the glasspane visible again...and, like i said above, adding mouse listeners to over 100 components that otherwise don't need them is something i'm trying to avoid.
B) I tested the following method on a single checkbox and it works, the checkmark is drawn, even with a visible glasspane, after recieving the redipatched event:checkbox.addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent event)
JCheckBox checkbox = (JCheckBox) event.getSource();
checkbox.setSelected(!checkbox.isSelected());
});So this isn't a matter of whether or not the glasspane is visible.
C) Adding some code (see below) in the glasspane mouselistener method revealed that the state of the JCheckBox did in fact not change so it's not only a matter of paint, but a matter of changing state. System.out.println("State: " + ((JCheckBox) component).isSelected());
glassPane.setVisible(false);
component.dispatchEvent(event2);
System.out.println("State: " + ((JCheckBox) component).isSelected());The print commands return "State: false" both before and after the dispatchEvent command. -
I have created a JTabbedPane with four tabs each containing a panel with a JTable in a scrollpane. When i run i can only view first tab, clciing on the others show an empty tab. It's probably something simple! Another class adds this JPanel into a JFrame. Here is my code:
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class EReg extends JPanel {
public EReg() {
JTabbedPane tabbedPane = new JTabbedPane();
String[] changeOptions = { "standard modules", "resit modules", "other modules",
"view all changes" };
JButton button1 = new JButton("Get Details");
JComboBox changes = new JComboBox(changeOptions);
changes.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String viewType = (String)cb.getSelectedItem();}
JPanel labelPanel1 = new JPanel(new GridLayout (2, 1));
JLabel iDLabel1 = new JLabel("Student ID:");
JLabel nameLabel1 = new JLabel("Name of Student:");
labelPanel1.add(iDLabel1);
labelPanel1.add(nameLabel1);
JPanel textPanel1 = new JPanel(new GridLayout (2, 1));
JTextField studID1 = new JTextField();
JTextField name1 = new JTextField();
textPanel1.add(studID1);
textPanel1.add(name1);
JPanel topPanel = new JPanel();
topPanel.setLayout(new GridLayout(1,4));
topPanel.add(labelPanel1);
topPanel.add(textPanel1);
topPanel.add(changes);
topPanel.add(button1);
JTable viewTable = new JTable();
JPanel viewPanel = new JPanel(new BorderLayout());
viewPanel.add(topPanel, BorderLayout.NORTH);
viewPanel.add(viewTable, BorderLayout.CENTER);
tabbedPane.addTab("View", viewPanel);
tabbedPane.setSelectedIndex(0);
JPanel updatePanel = new UpdatePanel();
tabbedPane.addTab("Update", viewPanel );
JPanel approvePanel = new ApprovePanel();
tabbedPane.addTab("Approve", viewPanel);
JPanel courseDetPanel = new CourseDetPanel();
tabbedPane.addTab("Course Details", viewPanel);
setLayout(new GridLayout(1, 1));
add(tabbedPane);Here is the full code with the tabs...each class compiles but when run, it doesnt show the panel, "vPanel", it just shows an empty panel instead. Thanx.
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class EReg extends JPanel {
public EReg() {
ViewPanel vPanel = new ViewPanel( );
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("View",null, vPanel,"");
tabbedPane.setSelectedIndex(0);
setLayout(new GridLayout(1, 1));
add(tabbedPane);
public static void main(final String[] args) {
JFrame frame = new JFrame("e-Reg Logged in as " );
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
frame.getContentPane().add(new EReg(),
BorderLayout.CENTER);
frame.setSize(800, 500);
frame.setVisible(true);
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ViewPanel extends JPanel
{ JPanel viewPanel;
public JPanel ViewPanel()
{ String[] changeOptions = { "standard modules", "resit modules", "other modules",
"view all changes" };
JButton button1 = new JButton("Get Details");
JComboBox changes = new JComboBox(changeOptions);
changes.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String viewType = (String)cb.getSelectedItem();}
JPanel labelPanel1 = new JPanel(new GridLayout (2, 1));
JLabel iDLabel1 = new JLabel("Student ID:");
JLabel nameLabel1 = new JLabel("Name of Student:");
labelPanel1.add(iDLabel1);
labelPanel1.add(nameLabel1);
JPanel textPanel1 = new JPanel(new GridLayout (2, 1));
JTextField studID1 = new JTextField();
JTextField name1 = new JTextField();
textPanel1.add(studID1);
textPanel1.add(name1);
JPanel topPanel = new JPanel();
topPanel.setLayout(new GridLayout(1,4));
topPanel.add(labelPanel1);
topPanel.add(textPanel1);
topPanel.add(changes);
topPanel.add(button1);
JTable viewTable = new JTable();
viewPanel = new JPanel(new BorderLayout());
viewPanel.add(topPanel, BorderLayout.NORTH);
viewPanel.add(viewTable, BorderLayout.CENTER);
return viewPanel;
} -
Able to change the borders of panels etc. but not tabbedpane???
hi!
i am able to set the borders of panels, frames, almost everything to lineborder but when i do this for tabbedpanes, nothing happens and i still get shadowy borders for it...
what culd be the reason??/This adds a rectangular border around the entire tabbedPane. (However, I suspect that this is not what you are trying to do)
tabbedPane.setBorder( BorderFactory.createLineBorder(Color.red) );
I think this is what your are asking for. (Add this code at the start of your program);
UIManager.put("TabbedPane.highlight", Color.blue );
UIManager.put("TabbedPane.lightHighlight", Color.blue );
UIManager.put("TabbedPane.selectHighlight", Color.blue );
UIManager.put("TabbedPane.shadow", Color.red );
UIManager.put("TabbedPane.darkShadow", Color.red ); -
How to change tabs in tabbedPane using buttons
I have designed 2 tabs using tabbedPane.
In the first tab I have a button. When I click on the button, I want it to automatically to switch to the second tab without having to click on the tab itself.Thank You!!
That worked brilliantly :) -
How can I change the font of the titles in a JTabbedPane
Hi
I use a JTabbedPane in a project and use windows LookAndFeel.
I want to distinguish the selected Tab titels by changing the font of the title. Is there anybody who can help me. I can not find any component used as the title. They are only there when I create the tabs with.
myTabbedPan.addTab("aTitle",aPanel);
How TabbedPan use the string "aTitle" to create Tab "Buttons". Is there a component or... I can not get it
Thanks
nan2000Unfortunately, you have to sub-class the WindowsTabbedPaneUI to do that, and override the convenient methods.
After that, you have to specify to the UIManager this new class it have to use to display the JTabbedPane components.
Denis -
Changing background color in JTable, only changes one row at a time...
I'm trying to change the color of rows when the 5th column meets certain criteria. I think I'm very close, but I've hit a wall.
What's happening is the row will change color as intended when the text in the 5th column is "KEY WORD", but when I type "KEY WORD" in a different column it will set the first row back to the regular colors. I can easily see why it's doing this, everytime something is changed it rerenders every cell, and the listener only checks the cell that was just changed if it met the "KEY WORD" condition, so it sets every cell (including the previous row that still meets the condition) to the normal colors. I can't come up with a good approach to changing the color for ALL rows that meet the condition. Any help would be appreciated.
In this part of the CellRenderer:
if (isSelected)
color = Color.red;
else
color = Color.blue;
if (hasFocus)
color = Color.yellow;
//row that meets special conditions
if(row == specRow && col == specCol)
color = color.white; I was thinking an approach would be to set them to their current color except for the one that meets special conditions, but the two problems with that are I can't figure out how to getColor() from the table, and I'm not sure how I would initially set the colors.
Here's the rest of the relevant code:
public void tableChanged(TableModelEvent e)
int firstRow = e.getFirstRow();
int lastRow = e.getLastRow();
int colIndex = e.getColumn();
if(colIndex == 4)
String value = (String)centerTable.getValueAt(firstRow, colIndex);
// check for our special selection criteria
if(value.equals("KEY WORD"))
for(int j = 0; j < centerTable.getColumnCount(); j++)
CellRenderer renderer =
(CellRenderer)centerTable.getCellRenderer(firstRow, j);
renderer.setSpecialSelection(firstRow, j);
import javax.swing.table.*;
import javax.swing.*;
import java.awt.Component;
import java.awt.Color;
public class CellRenderer extends DefaultTableCellRenderer
int specRow, specCol;
public CellRenderer()
specRow = -1;
specCol = -1;
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row, int col)
setHorizontalAlignment(JLabel.CENTER);
Color color = Color.green;
if (isSelected)
color = Color.red;
else
color = Color.blue;
if (hasFocus)
color = Color.yellow;
if(row == specRow && col == specCol)
color = color.white;
//setForeground(color);
setBackground(color);
setText((String)value);
return this;
public void setSpecialSelection(int row, int col)
specRow = row;
specCol = col;
}If I'm still stuck and more of my code is needed, I'll put together a smaller program that will isolate the problem tomorrow.That worked perfectly for what I was trying to do, but I've run into another problem. I'd like to change the row height when the conditions are met. What I discovered is that this creates an infinite loop since the resizing triggers the renderer, which resizes the row again, etc,. What would be the proper way to do this?
Here's the modified code from the program given in the link. All I did was declare the table for the class, and modify the if so I could add the "table.setRowHeight(row, 30);" line.
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
public class TableRowRenderingTip extends JPanel
JTable table;
public TableRowRenderingTip()
Object[] columnNames = {"Type", "Company", "Shares", "Price", "Boolean"};
Object[][] data =
{"Buy", "IBM", new Integer(1000), new Double(80.5), Boolean.TRUE},
{"Sell", "Dell", new Integer(2000), new Double(6.25), Boolean.FALSE},
{"Short Sell", "Apple", new Integer(3000), new Double(7.35), Boolean.TRUE},
{"Buy", "MicroSoft", new Integer(4000), new Double(27.50), Boolean.FALSE},
{"Short Sell", "Cisco", new Integer(5000), new Double(20), Boolean.TRUE}
DefaultTableModel model = new DefaultTableModel(data, columnNames)
public Class getColumnClass(int column)
return getValueAt(0, column).getClass();
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("Alternating", createAlternating(model));
tabbedPane.addTab("Border", createBorder(model));
tabbedPane.addTab("Data", createData(model));
add( tabbedPane );
private JComponent createAlternating(DefaultTableModel model)
JTable table = new JTable( model )
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Component c = super.prepareRenderer(renderer, row, column);
// Alternate row color
if (!isRowSelected(row))
c.setBackground(row % 2 == 0 ? getBackground() : Color.LIGHT_GRAY);
return c;
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.changeSelection(0, 0, false, false);
return new JScrollPane( table );
private JComponent createBorder(DefaultTableModel model)
JTable table = new JTable( model )
private Border outside = new MatteBorder(1, 0, 1, 0, Color.RED);
private Border inside = new EmptyBorder(0, 1, 0, 1);
private Border highlight = new CompoundBorder(outside, inside);
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Component c = super.prepareRenderer(renderer, row, column);
JComponent jc = (JComponent)c;
// Add a border to the selected row
if (isRowSelected(row))
jc.setBorder( highlight );
return c;
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.changeSelection(0, 0, false, false);
return new JScrollPane( table );
public JComponent createData(DefaultTableModel model)
table = new JTable( model )
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Component c = super.prepareRenderer(renderer, row, column);
// Color row based on a cell value
if (!isRowSelected(row))
c.setBackground(getBackground());
String type = (String)getModel().getValueAt(row, 0);
if ("Buy".equals(type)) {
table.setRowHeight(row, 30);
c.setBackground(Color.GREEN);
if ("Sell".equals(type)) c.setBackground(Color.YELLOW);
return c;
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.changeSelection(0, 0, false, false);
return new JScrollPane( table );
public static void main(String[] args)
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
public static void createAndShowGUI()
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Table Row Rendering");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add( new TableRowRenderingTip() );
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}Edited by: scavok on Apr 26, 2010 6:43 PM -
How to align text to left of tabbedpane
I am trying to align my text in a tabbedpane and it only centers, is there a way to make the text within the tab left aligned?
Here is my code:
================
tabbedPane.addTab("Step 1/Campaign",null, new CampaignPanel(),"General Campaign Information");
tabbedPane.addTab("Step 2/MOP", null, new MOPPanel(),"Method of Payment Entry");
tabbedPane.addTab("Step 3/Shipping", null, new ShipPanel(),"Shipping Information Entry");
I have tried to use HTML in the text by <P align="left">some text</P>, but that didn't do it.
thanks
Dean
tabbedPane.addTab("Step 4/Leads", null, new LeadsPanel(),"Load and test Campaign Leads");If you want to change the layout of the text inside a tab, one solution is to override the layoutLabel method the BasicTabbedPaneUI... it's kinda complicated so I'm hoping someone out there has a better solution.
Anyway, the line to look at in layoutLabel is:
SwingUtilities.layoutCompoundLabel(
(JComponent) tabPane,
metrics,
title,
icon,
SwingUtilities.CENTER,
SwingUtilities.CENTER,
SwingUtilities.CENTER,
//SwingUtilities.TRAILING,
SwingUtilities.CENTER,
tabRect,
iconRect,
textRect,
textIconGap);
Here you can specify where things go in the tab. Arguments 5-8 deal with the text position and text position in relation to the image. -
How to change selected pane's color in a JTabbedPane ?
Hi there !
I'm tryin' to change selected pane's color (default : light gray) in a JTabbedPane.
I tried to use the following code :
UIManager.put("TabbedPane.selected", new Color(255,255,200));
but it doesn't seem to work.
Any idea ?
Thanks.For me, there is no TabbedPane.selected filed in TabnedPaneUI....
try with
UIManager.put("TabbedPane.highlight", new Color(255,255,200));
or
UIManager.put("TabbedPane.background", new Color(255,255,200)); -
I know this problem has been answered in similar form previously., but my version is a little different. I have a JList of fonts. When a font is selected on the list, changes should be applied to a JTextArea. I have my <JTextArea>.setFont(Font f) command in the valueChanged method of my class. However, the font does not change, neither visually nor internally. What's the problem? Thanks in advance for all help.
Update: I've gotten the font working, stupid mistake on my part so sorry for the trouble, but the color chooser still refuses to work...
Here's the code as requested (I've omitted much that i'm pretty positive is unrelated):
class FontDialog extends JDialog implements ListSelectionListener, ChangeListener { //this is an inner class
MyFont font = new MyFont("Times New Roman", Font.PLAIN, 12); //font object for manipulation - this is a class of mine
Object[] fontItems = font.getFontList(),
styleItems = {"Regular", "Bold", "Italic", "Bold Italic "},
sizeItems = {"6", "8", "10", "12", "14", "16", "18", "20", "24", "48"};
JList fontList, styleList, sizeList;
JTextField fontField, styleField, sizeField;
JTextArea preview;
JColorChooser jcc;
public FontDialog(JFrame owner, String name) {
super(owner, name);
font = new MyFont("Times New Roman", Font.PLAIN, 12); //font object for manipulation
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
panel.add(createFontPane(), c); //code omitted
c.gridx = 1;
c.gridy = 0;
panel.add(createSizePane(), c); //code omitted
c.gridx = 0;
c.gridy = 1;
panel.add(createStylePane(), c); //code omitted
c.gridx = 1;
c.gridy = 1;
panel.add(createPreviewPane(), c);
tabbedPane.addTab("Text", panel);
jcc = new JColorChooser(Color.BLACK);
jcc.setPreviewPanel(new JPanel());
tabbedPane.addTab("Color", jcc);
tabbedPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
add(tabbedPane, BorderLayout.CENTER);
private JTextArea createPreviewPane() {
preview = new JTextArea(" AaBbCcDd ");
preview.setFont(font);
preview.setEditable(false);
preview.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
return preview;
public void valueChanged(ListSelectionEvent e) {
JList list = (JList)e.getSource();
int i = list.getSelectedIndex();
if(list == fontList) {
fontField.setText((String)fontItems); //update given list
font.setFont((String)fontItems[i]); //update preview area
else if(list == sizeList) {
sizeField.setText((String)sizeItems[i]); //update given list
font.setSize(new Integer((String)sizeItems[i])); //update preview area
else {
styleField.setText((String)styleItems[i]); //update given list
switch(i) { //update preview area
case(0):
font.setStyle(Font.PLAIN);
break;
case(1):
font.setStyle(Font.BOLD);
break;
case(2):
font.setStyle(Font.ITALIC);
break;
case(3):
font.setStyle(Font.BOLD + Font.ITALIC);
break;
preview.setFont(font);
public void stateChanged(ChangeEvent e) {
preview.setForeground(jcc.getColor()); -
JTabbedPane: Contents changes in different tab.
My applet consists of a jtabbedpane with 3 tabs. each tab consists of a panel, which in turn consists of a jComboBox and jTextArea. my problem is when i click on an item in jComboBox of tab 1, nothing happen with jTextArea in tab 1, but changes are in jTextArea of tab 3. actionlistener of the jComboBox cant cannot be compile if i put jTextArea as local var. so my jTextArea is a global var. please advice.
Im implementing RMI application btw, this is the client code:
public class Client extends JApplet
JTabbedPane tabbedPane;
JTextArea txt;
JComboBoc jcb;
String str;
public void init()
try
tabbedPane = new JTabbedPane();
JComponent tab1 = setPanel("ABC");
tabbedPane.addTab("ABC",tab1);
//tab2 and tab3
//setting layout
catch (Exception ex)
protected void getPanel()
try
//RMI connection to server goes here
//RMI accessing server objects goes here
//s.getText() is server object
//JTextArea is set for different content type for diff tab
txt.setText(s.getText());
catch (Exception ex)
protected JComponent setPanel(String input)
JPanel pnl = new JPanel();
txt = new JTextArea(20,60);
txt.setLineWrap(true);
txt.setWrapStyleWord(true);
getPanel();
jcb = new JComboBox(itemList);
jcb.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
JComboBox cb = (JComboBox)e.getSource();
str = (String)cb.getSelectedItem();
getPanel();
//setting layout
return pnl;
When the applet is initialize, everything goes fine. what i mean is tab1 has its own content of JTextArea, so do tab2 and tab3. but when i click on an item of JComboBox in tab1 or tab2, changes made are at JTextArea of tab3.
If JTextArea is declared as local in setPanel, the getPanel would not access the JTextArea. -
Change Color of Disable Tab in JTabbedPane
Hello Friends,
I have one JTabbedPane in my Application.
In that one Tab is Disable.
I want to change default Background and Foreground color of that tab.
Can u help me...
Thanks in Advance,
Nishith Shah.hii,
please I can't find out any DisableColor or something similair for defaultTabbedPaneUI, please try (unselect)
package jtabs;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
public class TestTabbedPane extends JFrame {
JTabbedPane tabbedPane;
public TestTabbedPane() {
tabbedPane = new JTabbedPane();
tabbedPane.setPreferredSize(new Dimension(300, 200));
getContentPane().add(tabbedPane);
JPanel panel = new JPanel();
tabbedPane.add(panel, "null");
JTextField one = new JTextField("one");
tabbedPane.add(one, "one");
JTextField two = new JTextField("two");
tabbedPane.add(two, "two");
tabbedPane.setEnabledAt(2, false);
/*UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
UIManager.put("TabbedPane.highlight", new Color(255, 0, 0));
UIManager.put("TabbedPane.lightHighlight", new Color(0, 255, 0));
UIManager.put("TabbedPane.darkShadow", new Color(0, 255, 0));
UIManager.put("TabbedPane.shadow",new Color(0, 0, 255));
UIManager.put("TabbedPane.light" , new Color(0, 255, 0));
UIManager.put("TabbedPane.foreground", new Color(0, 0, 0));
UIManager.put("JTabbedPane.font", new Font("Dialog", Font.ITALIC, 12));
UIManager.put("TabbedPane.selected", new Color(255, 0, 0));
UIManager.put("disable", new Color(255, 0, 0));
UIManager.put("TabbedPane.selectHighlight" , new Color(0, 0, 0));*/
//UIManager.put("TabbedPane.background", new Color(0, 0, 0));
//SwingUtilities.updateComponentTreeUI(tabbedPane);
/*tabbedPane.setTitleAt(2, "<html><font color=" +
(tabbedPane.isEnabledAt(2) ? "black" : "red") + ">" +
tabbedPane.getTitleAt(2) + "</font></html>");*/
public static void main(String args[]) {
TestTabbedPane frame = new TestTabbedPane();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
} value are from
import javax.swing.*;
import java.util.*;
public class GetUIManagerList {
public static void main(String[] args) {
UIDefaults defaults = UIManager.getDefaults();
System.out.println(defaults.size() + " properties defined !");
System.out.println("-----------------------------------");
String[] colName = {"Key", "Value"};
String[][] rowData = new String[defaults.size()][2];
int i = 0;
for (Enumeration e = defaults.keys(); e.hasMoreElements(); i++) {
Object key = e.nextElement();
rowData[ 0] = key.toString();
rowData[i][ 1] = "" + defaults.get(key);
System.out.println(rowData[i][0] + " ,, " + rowData[i][1]);
please could I ask camickr or DarrylBurke how to overide disabled label in JTabbedPane (without Shadows), with using their SwingUtils
... kopik -
Color of the selected tab in a tabbedpane
I wander if anyone knows how to change the color of a tab when it is selected. I have tried to use; "tabbedPane.setBackgroundAt(1,rgdcolor)" , where 1 is the tab chosen and rgb is my predifined color, but the color of the tab stays unchanged.
/annaHere is some code that will display all the UIManager properties and the default values.
import javax.swing.*;
import java.util.*;
public class ShowUIManager {
public static void main(String[] args) {
UIDefaults defaults = UIManager.getDefaults();
System.out.println("Count Item = " + defaults.size());
String[ ] colName = {"Key", "Value"};
String[ ][ ] rowData = new String[ defaults.size() ][ 2 ];
int i = 0;
for(Enumeration e = defaults.keys(); e.hasMoreElements(); i++){
Object key = e.nextElement();
rowData[ i ] [ 0 ] = key.toString();
rowData[ i ] [ 1 ] = ""+defaults.get(key);
System.out.println(rowData[0]+" ,, "+rowData[i][1]);
JFrame f = new JFrame("UIDefaults Key-Value sheet");
JTable t = new JTable(rowData, colName);
f.setContentPane(new JScrollPane(t));
//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true); -
JTabbedPane - Catching tab selection change
I want to catch each tab selection change in my JTabbedPane.
When I used ChangeListener, my program was unable to correctly
indicate selected tab in some cases, i.e.:
JTabbedPane contains two tabs: 0,1.
Tab 0 was selected.
Tab 0 was deleted.
In this case JTabbedPane selects tab 1, but selected index remains
unchanged and stateChanged is not called. How can I catch this?This trick is working, but you see, the problem is more
complicated. The problem is that stateChanged() doesn't work
when index remains unchanged. This is also true for insertTab().
Both insertTab() and removeTabAt() (and maybe smth. else) causes this problem.
Maybe, possible solution will be to override some method of
JTabbedPane, responsible for activating a tab like this...?
tabbedPane = new JTabbedPane {
activateTab(...) {
super.activateTab(...);
firePropertyChange(...);
}But what is the methods prototype and can it be overriden
at all??
In the deep sources of swing :) I've found such tricks:
In JTabbedPane.insertTab():accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
null, component);In JTabbedPane.removeTabAt():accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
component, null);I'm almost convinced that this is the point. But!
I've never worked with Accesibility :(
And I couldn't find out what to do having only swing sources.
Need help.
Maybe you are looking for
-
Powerbook G4 sounds like it may explode - failing hard disk?
Last night during a World of Warcraft adventure, my trusty Powerbook of about four years started making a noise something like a small, accelerating race car. As far as I can tell, the sound was coming from the upper left area of the laptop. In a pan
-
How do I count parts with a fiber optic sensor using the NI-1772 and VBAI 2011?
I'm inspecting parts using the NI-1772. Just after the camera, bad parts are ejected when they pass by a fiberoptic sensor. I want to use another sensor after that to verify the number of good parts, so that I can be sure the bad parts have been ej
-
User Settings reset upon restart! everytime!
I just bought a MBP several weeks ago and I am very happy with it , BUT , after a recent software update everytime my computer shuts down or I restart it completly resets my dock and every user setting I applied almost like a fresh system restore. No
-
I had some bookmarks on my Mozilla browser.I don't remember the account on whose name it was signed up.But since we had to upgrade the operating system. the bookmarks and browsing history got deleted.How to restore them back?
-
CSS CItrix Nfuse Connections Drop
We are using a CSS-11501 version 7.5 to load balance SSL connections to a pair of Citrix Web Interface servers. The CSS is connected to a DMZ interface of an ASA5520 on one side, and a 3550 with the web interface servers on the other side. Citrix app