• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

how to fix the JLabel Text value in Swings

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to fix the length of the JLabel text in my application.

For example: JLabel test=new JLabel("Selected File Testing");

If i use the above string,then my design gets collapsed.

how to fix the length of the JLabel Text?

Please help me to resolve this issue...

here is my code...


getContentPane().setLayout(new GridBagLayout());
getContentPane().setBounds(500, 300, 500, 300);
getContentPane().setBackground(Color.decode("#C1CDAD"));
GridBagConstraints c = new GridBagConstraints();

c.anchor = GridBagConstraints.FIRST_LINE_START;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 0);
c.gridwidth = 1;
c.weightx=1.0f;
c.weighty=1.0f;
// c.gridx = 0;
c.gridy = 1;
getContentPane().add(fileSelectLabel, c);

c.anchor = GridBagConstraints.LINE_START;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 0);
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 1;
getContentPane().add(statusLabel, c);

c.anchor = GridBagConstraints.PAGE_START;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 10);
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 0;
getContentPane().add(pathField, c);
pathField.setEditable(false);
pathField.setBackground(Color.white);
pathField.setBorder(BorderFactory.createLineBorder(Color.decode("#98AFC7")));

c.anchor = GridBagConstraints.FIRST_LINE_END;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 10);
c.gridwidth = 1;
c.gridx = 2;
c.gridy = 0;
getContentPane().add(browseButton, c);

c.anchor = GridBagConstraints.LINE_END;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 10);
c.gridwidth = 1;
c.gridx = 2;
c.gridy = 1;
getContentPane().add(uploadButton, c);

c.anchor = GridBagConstraints.LINE_END;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 10);
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = 2;
c.gridy = 2;
getContentPane().add(cancelButton, c);

c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(20, 10, 20, 10);
c.gridwidth = 3;
c.gridheight = 1;
c.gridx = 0;
c.gridy = 5;
getContentPane().add(uploadProgress, c);

c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(10, 10, 10, 10);
c.gridwidth = 1;
c.gridheight = 2;
c.gridx = 1;
c.gridy = 1;
getContentPane().add(statusArea, c);
statusArea.setEditable(false);
statusArea.setBorder(BorderFactory.createLineBorder(Color.decode("#98AFC7")));

c.anchor = GridBagConstraints.NORTH;
c.fill = GridBagConstraints.CENTER;
c.insets = new Insets(0, 5, 0, 5);
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = 1;
c.gridy = 4;
getContentPane().add(bytesLabel, c);
bytesLabel.setVisible(false);

c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.LAST_LINE_START;
c.insets = new Insets(0, 5, 0, 5);
c.gridwidth = 3;
c.gridheight = 1;
c.gridx = 0;
c.gridy = 6;
getContentPane().add(warningLabel, c);
warningLabel.setVisible(false);
warningLabel.setForeground(Color.red)
 
You don't like waffles? Well, do you like this tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic