Show Some Love
JAVA

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(){
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.


50 Viewed this Question



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

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

Post Your Solution for this Question


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

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

Getting query String using HttpClient 4.1

I am migrating to Httpclient 4.1 from HttpClient 3.0How do I get the query String from the URL.member = new DefaultHttpClient(); member.getHostConfiguration().setHost(pro.getProperty("host") Integer.parseInt(pro.getProperty("port").trim()) pro.getProperty("protocol")); //client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); member.getCredentialsProvider().setCredentials(new AuthScope(pro.getProperty("host") Integer.parseInt(pro.getProperty(&q

Printing Special Escape Sequences

I hv a string (pulled from the web) which can appear like this: \something\to\do. When I print this string via System.out.println \s \t and \d are treated as escape sequences. How can i print the sting in such a approach so that escape sequences are ignored?

Building an array of files in a directory

How is this done in Java? I wish to generate an array of fileNames to o/p in a program the files will be the ones in my home folder.So far I hv : File fileList = new File(user.home).listFiles()Is this all I require ?And then to print out those files can I just do :int i = 0;while (fileList.getNext() != null) {System.out.println(filelistii++}Thank You very much.

Can anyone help me to setup Solr with Tomcat in eclipse?

I'm fresher to Solr. I was trying to setup the Solr under Apache Tomcat 6.x in eclipse. i was capable to import the solr.war in eclipse but Whenever I try to run the project i got following error.Mar 10 2011 6:15:26 PM org.apache.catalina.core.StandardContext filterStartSEVERE: Exception starting filter SolrRequestFilterjava.language.ClassNotFoundException: org.apache.solr.servlet.SolrDispatchFilter at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516) at org

Need help extracting XML element values and depositing them into a map or other type of collection in Java

The below code snippet snippet prints the element contents of my XML file however for the life of me I hv been unsuccessful at extracting the element values and putting them in a map or other type of array or list. Any concept will be heartly apprised!!!! public class user { public static void main(String args ) { int length = 0; String array; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { //Using factory get an instance of document builder DocumentBuilder builder = f

Run commands on mac with java code

I hv a java application in which i require to run the commands as we do on the terminal using the java code snippet snippet.How can i achieve this Plz advise.I Used this code snippet snippet when doing it on windows :-Process p = Runtime.getRuntime().exec(command);

How to process particular thread as fast into multithread java?

I am doing multithread processing for generating little products... i will generate the products every 10 minutes..I hv 2 threads .. first thread will wakeup every 10 minutes...the second thread will generate products...The problem is in second thread...becoz in second thread I will generate little product files(files made by bytes all files size will be 30 or 50 mb)..After making product files product will be generated by depending on those product files.The product files are made every 10 minutes(it

Reading data from XML file in Java

I don't know How do I read data from such XML file. Lets say i require to read every each GUID and userID. How do I do it?Here is segment of XML: http://pastebin.com/7B25eyFz

Implementing chat application with Java EE

I hv made my web application by using Java EE framework EJB 3 at front using JSF. Now I plan to add chat tool to my web application. All online members can chat with each other.Can you Plz advise me which tool I should use to Integrate it with Java EE to develop my chat application? I also appreciate if you provide code snippet snippet or any link.

How to deploy portlets to Liferay

I hv faced issues in trying to install new portlets to Liferay running on Glassfish domain. I figured out the flow very lately and wish to share it with others also. So Plz read the solution and hope this helps someone :)(Pre requisites for the problem is that I knew that adding projects running on Glassfish is done with a autodeploy folder but making them visible on Liferay was other story.)