• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how to fix the JLabel Text value in Swings

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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)
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic