• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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)
 
Create symphonies in seed and soil. For this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic