🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1472

JButton auto resize??

#1472
From: Rudy
Date: Sun, 30 Nov 2003 22:35
36 lines
2278 bytes
I have the following code:

public void add(final JButton component) {
    component.addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        mComponent = component;
        //mComponent.setBackground(Color.BLUE);
      }
    });
    mComponent = component;
    mComponent.setSize(w, h);
    mComponent.setLocation(x, y);
    mComponent.setMinimumSize(new Dimension(120, 120));
    mComponent.setMaximumSize(new Dimension(150, 150));
    mComponent.setPreferredSize(new Dimension(130, 130));
    mComponent.setFont(new Font("Dialog", 0, 9));
    mComponent.setBorder(BorderFactory.createEmptyBorder());
    mComponent.setBackground(Color.WHITE);
    mComponent.setMargin(new Insets(1, 1, 1, 1));
    mComponent.setText(text);
    mComponent.setVerticalAlignment(SwingConstants.TOP);
    mComponent.setHorizontalAlignment(SwingConstants.CENTER);
    mComponent.setIcon(logo2);
    super.add(mComponent);
    repaint();
  }

the problem i am having is that i would like the button to resize depending
on what text is entered in the setText() method.  I find that the button
uses the setSize method and always stays at this size but does not use the
set...Size methods. However if i remove the setSize method then the button
is not displayed.  How can i ensure the button is size around the text
properly.

Thanks
Rudy
Technical Details
Message-ID: <3fca70a4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,d747d5f574c277f5,start
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-11-30 14:39:20 PST
Reply-To: "Rudy" <rhentzen@hotmail.com>
From: "Rudy" <rhentzen@hotmail.com>
Newsgroups: borland.public.jbuilder.java.swing
Subject: JButton auto resize??
Date: Sun, 30 Nov 2003 22:35:13 -0000
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 81.86.182.21
Message-ID: <3fca70a4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1070231716 81.86.182.21 (30 Nov 2003 14:35:16 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail