Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2313 > unrolled thread

JButton.setMargin broken

Started by"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
First post2011-04-27 15:38 +0000
Last post2011-04-27 15:38 +0000
Articles 7 — 3 participants

Back to article view | Back to comp.lang.java.gui


Contents

  JButton.setMargin broken "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
    Re: JButton.setMargin bro "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
      Re: JButton.setMargin bro "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
        Re: JButton.setMargin bro "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
    Re: JButton.setMargin bro "usenet" <usenet@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
      Re: JButton.setMargin bro "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000
    Re: JButton.setMargin bro "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000

#2313 — JButton.setMargin broken

From"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectJButton.setMargin broken
Message-ID<i692d3t1r2i1dr3jbhmsjmt3gkib3i7tc9@4ax.com>
  To: comp.lang.java.gui
It seems that Swing ignores JButton.setMargin. Is that your finding?
Is this a bug or is there some excuse for it?

Here is my workaround - using a compound border to get the margin.

public class JEButton extends JButton {
    /**
     * constructor
     *
     * @param text string to label the JButton
     */
    public JEButton( String text )
        {
        super( text );
        this.setFocusPainted( false );
        this.setBorder( border );
        this.setFont( new Font( "Dialog", Font.BOLD, 16 ) );
        // set margin does not work.

        // Leave foreground and background alone to get gradient.
        // Client should do a setToolTip, possibly a requestFocus
        }

    private static final Border border;

    static
        {
        final Border innerBorder =
                BorderFactory.createEmptyBorder( 2, 5, 2, 5 );
        final Border outerBorder =
BorderFactory.createRaisedBevelBorder();
        border = BorderFactory.createCompoundBorder( outerBorder,
innerBorder );
        }
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2314 — Re: JButton.setMargin bro

From"Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectRe: JButton.setMargin bro
Message-ID<7742e32606cba@uwe>
In reply to#2313
  To: comp.lang.java.gui
Roedy Green wrote:
>It seems that Swing ignores JButton.setMargin. Is that your finding?

No.  This code produces one small and one big 
button here, using Java 1.6.

<sscce>
import java.awt.*;
import javax.swing.*;

class ButtonMargin {

  public static void main(String[] args) {
    JPanel p = new JPanel();

    JButton btn1 = new JButton("button 1");
    p.add(btn1);

    JButton btn2 = new JButton("button 2");
    Insets insets = new Insets(100,100,100,100);
    btn2.setMargin(insets);
    p.add(btn2);

    p.validate();

    JOptionPane.showMessageDialog( null, p );
  }
}
</sscce>

>Is this a bug or is there some excuse for it?

The layouts being used in the code that fails?

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via http://www.javakb.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2315 — Re: JButton.setMargin bro

From"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectRe: JButton.setMargin bro
Message-ID<nki2d3pdbqnlgeh7uounubfqnk58lictdm@4ax.com>
In reply to#2314
  To: comp.lang.java.gui
On Sun, 26 Aug 2007 07:37:49 GMT, "Andrew Thompson" <u32984@uwe>
wrote, quoted or indirectly quoted someone who said :

>No.  This code produces one small and one big 
>button here, using Java 1.6.

Maybe it is an interaction with GridBagLayout.
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2318 — Re: JButton.setMargin bro

From"Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectRe: JButton.setMargin bro
Message-ID<7746b41e9f554@uwe>
In reply to#2315
  To: comp.lang.java.gui
Roedy Green wrote:
>>No.  This code produces one small and one big 
>>button here, using Java 1.6.
>
>Maybe it is an interaction with GridBagLayout.

Maybe.  Without code it is hard to tell.

GBL does tend to muck up when there is no minimum*
size set for a component, when that component cannot
be assigned its preferred size.

* As far as I vaguely recall.  There are very few things
cannot be achieved with other layouts, so I tend to avoid
using it, mostly.

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via http://www.javakb.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2316 — Re: JButton.setMargin bro

From"usenet" <usenet@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectRe: JButton.setMargin bro
Message-ID<0T4bucbdI25e@uni.chka.de>
In reply to#2313
  To: comp.lang.java.gui
Roedy Green <see_website@mindprod.com.invalid> wrote:
> It seems that Swing ignores JButton.setMargin. Is that your finding?
> Is this a bug or is there some excuse for it?

The margin is modelled as an extra border (e.g.
javax.swing.plaf.basic.BasicBorders.MarginBorder), usually installed
by the LookAndFeel. If you replace a button's border, put a margin
border (using CompoundBorder) in the place where you want to have it,
relative to the other border(s).


Christian

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2320 — Re: JButton.setMargin bro

From"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectRe: JButton.setMargin bro
Message-ID<opa4d3tnmielsm749243tqtjf008g7munj@4ax.com>
In reply to#2316
  To: comp.lang.java.gui
On Sun, 26 Aug 2007 11:17:52 +0000 (UTC), usenet@chka.de (Christian
Kaufhold) wrote, quoted or indirectly quoted someone who said :

>
>The margin is modelled as an extra border (e.g.
>javax.swing.plaf.basic.BasicBorders.MarginBorder), usually installed
>by the LookAndFeel. If you replace a button's border, put a margin
>border (using CompoundBorder) in the place where you want to have it,
>relative to the other border(s).

That's what I did.  Thanks for explaining why it failed.
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#2321 — Re: JButton.setMargin bro

From"Roedy Green" <roedy.green@THRWHITE.remove-dii-this>
Date2011-04-27 15:38 +0000
SubjectRe: JButton.setMargin bro
Message-ID<nfc4d3tu93l7pndmir01ivqm4elithco78@4ax.com>
In reply to#2313
  To: comp.lang.java.gui
On Sun, 26 Aug 2007 07:01:17 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>It seems that Swing ignores JButton.setMargin. Is that your finding?
>Is this a bug or is there some excuse for it?

see http://mindprod.com/jgloss/jbutton.html#GOTCHAS
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web