Set size of a JLabel inside JToolbar


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(){
super();
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.areaCoordX.setHorizontalAlignment(JLabel.RIGHT);
this.areaCoordX.setOpaque(true);
this.areaCoordY = new JLabel("");
this.add(areaCoordX);
this.add(new JLabel(":"));
this.add(areaCoordY);
}
}
public void setCoordOfComponent(Point c){
this.areaCoordX.setText(""+c.x);
this.areaCoordY.setText(""+c.y);
}
}
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.setFloatable(false);
statusBar.setMaximumSize(new Dimension(2000 20));
}
public Gui() {
super();
getContentPane().setLayout(
new BoxLayout(getContentPane() BoxLayout.Y_AXIS));
buildStatusBar();
this.getContentPane().add(statusBar);
}}

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.



Get Source Code

  Views 29   Posted on : Saturday, May 25, 2013 1:39:08 PM
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.




Also See: