If I set Metal theme for Swing GUI, JButton border is painted around the whole button, but focus border is painted only around JButton's text and icon, so if text size is smaller than button size, the border appears inside button.
Most replies to this problem simply suggest to disable global focus border painting by
UIManager.getLookAndFeelDefaults().put("Button.focus", new ColorUIResource(new Color(0, 0, 0, 0)));
or per-button by jButton.setFocusPainted(false);
But I actually want focus border to be painted - like in Nimbus LAF around the whole button. I suppose I need to override focus painter with default one for Button.border, but can't find which one. Maybe someone can help me?
Related
I've made a JFrame with the next Properties:
setLayout(null)
setUndecorated(true)
setResizable(false)
within i've put a JLabel with one Icon(PNG image) in netbeans, and im looking for some soluction that disable the backgroud(full Transparent, and unactive) when the mouse moves THROUGH JFrame's Image(or someother component) BUT the mouse works different outside of the JLabel because JLabel Icon avoid any mouse action over the JLabel. But there's a default Gray background that doesnt exactly what i want.
We can see that mouse doesnt do anything on the JLabel(unless there were some component in the Frame)
Green = JFrame size.
And here the mouse change when moves through of the web page
im looking for some soluction that disable the backgroud(full Transparent, and unactive) when the mouse moves
Don't use full transparency.
If the pixels are not 100% transparent, then the MouseEvents will be handled by the frame.
From my main form I want to display a new form.
When the new form is opened, it needs to be treated as a child in that clicking on the parent brings forward the child for focus. JFrames aren't modal apparently, so I'm using:
JOptionPane.showOptionDialog(null, MYPANEL, "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{}, null);
...Where MYPANEL looks identical to what I need in my form.
This works 100% as intended EXCEPT that there is padding (about 20px or so) between the panel edges and the JOptionPane dialog frame.
How can I get rid of this?
Setting the border of the panel to an empty border with 0 as dimensions changed nothing.
Setting the border of the panel to an empty border with 0 as dimensions changed nothing.
You need to set the Border of the content pane of the dialog. Don't know if it will work on all LAF's but you can use the following for Metal and Windows:
UIManager.put("OptionPane.border", new EmptyBorder(0, 0, 0, 0) );
See UIManager Defaults for more information.
This will change the property for all option panes. So you may want to save the default border, create your option pane and then restore the original border for creating other option panes.
Maybe another option is to add an ContainerListener to the panel. Then you could handle the componentAdded(...) event. When the event is generated you can get the parent panel and remove the Border.
I am making a simple swing application and I want to add some titled borders to my components. The border on both of my JScrollPanes work fine, but the JTextField and the JButtons don't. Allow me to share some screen shots.
I just have simple code for this. i.e
TitledBorder border = new TitledBorder("Border");
convert.setBorder(border); //convert is the JButton
I don't see why it would not work for one thing, and work for the other. Can anyone help me out?
A JTextField and JButton both use a Border already. So the titled border works but it changes the appearance of the component because you lose the default Border.
I also agree that normally you don't use a TitledBorder for an individual component but I suppose you could try to use a CompoundBorder to see if it looks any better:
CompoundBorder border = new CompoundBorder(titledBorder, button.getBorder());
button.setBorder( border );
but then the problem with the above approach is that you lose dynamic repainting of the border when you press/release the mouse on the button.
I have a JPanel of null layout called MainPanel. Onclick of a button I am adding JTextpane on mainPanel. On first click I am creating a textpane of background color white. On second click I am creating another textpane of color blue. What I want is to place the blue textpane upon the white textpane, but the blue textpane is going behind the white textpane. How can I place it on white pane?
Code is very simple here. Onclick I am creating a new JTextpane, setting dimensions to it and placing it on the mainPanel.
Placing a sample screenshot which describes the issue better. Here the blue textpane has gone behind white textpane. I want it above white texpane. How do I do that?
If you want to stick with your current Components, (I think you should use kellax's solution, but I don't know if there's an extra requirement that's forcing you to use your current approach) you can look into Container.setComponentZOrder(Component comp, int index) to directly determine the order in which Components are displayed.
You will have to replace your JPanel "MainPanel" with a LayeredPanel.
Then you can say:
JLayeredPane mainPanel = new JLayeredPane();
JTextPane whitePane = new JTextPane("White text pane on top");
JTextPane bluePane = new JTextPane("Blue text pane behind");
mainPanel.add(whitePane, 2, 0);
mainPanel.add(bluePane, 1, 0);
Edit:
You can read more about the LayeredPane here: LayeredPane
I set the background of a JWindow completely transparent. Then I painted a rounded Rectangle (RGB: 0,0,0,100) in it's paint-Method and added a JLabel to the JWindows ContentPane. But when I try to repaint the JWindow to update the JLabel, it doesn't remove the old Rectangle and the old value of the JLabel. So the result is that my custom tooltip box (what it should be) gets less transparent and you cannot read the JLabels contents, because it overlays the old contens.
Is there any way to solve this problem?
BTW, if I don't repaint, it doesn't get less transparent, but the new contents of my JLabel overlays the old Contents, like it is, when I repaint.
First you should override paintComponent instead of paint and call super.paintComponent(g). You should leave JWindow opaque, because the component on the rearmost layer will clear the old contents. If all the layers are transparent you will end up with screen garbage.
See painting with Swing. Perhaps you really wanted to create translucent windows?