Set size of a JLabel inside JToolbar

This forum was posted on Saturday, May 25, 2013 1:39:08 PM

I hv little troubles setting the size of a JLabel component inserted into a JToolbar. I use the JLabel to show actual mouse coordinates but depending on the lenght of the number JLabel update it is size generating little nasty movements of my JToolbar components.
I am playing around with setSize setMinimumSize etc to overcome this issue but still no output. I know that the behavior of this methods update accordingly to the layout manager.
Which is the right method to define a fixed minimum dimension of a JLabel into a JToolbar?
this is my code snippet snippet :
public class EditorStatusBar extends JToolBar{
private JLabel areaCoordX;
private JLabel areaCoordY;
public EditorStatusBar(){
addSeparator(new Dimension(100 this.getSize().height));
this.areaCoordX = new JLabel(" ");
this.areaCoordX.setMinimumSize(new Dimension(80 10));
this.areaCoordX.setPreferredSize(new Dimension(80 10));
this.areaCoordY = new JLabel("");
this.add(new JLabel(":"));
public void setCoordOfComponent(Point c){
public class Gui extends JFrame implements ActionListener ItemListener ChangeListener{
private EditorStatusBar statusBar;
public static void main(String args) {
new Gui();
private void buildStatusBar(){
statusBar = new EditorStatusBar();
statusBar.setMaximumSize(new Dimension(2000 20));
public Gui() {
new BoxLayout(getContentPane() BoxLayout.Y_AXIS));

When I am updating the value with setCoordOfComponent() it works if i set both minimum and liked size but when the mouse is for illustration over the JMenu JPanel size decrease.

 Views 43 Get Source Code >>
Related Tags:

Replies on "Set size of a JLabel inside JToolbar" :

Nobody has replied on this post , be first to post answer.

Post Your Answer/Comment:

Please Login first to post Reply !

Note: Please Put Code into <code></code> block.

Threads related to "Set size of a JLabel inside JToolbar":