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


Groups > comp.lang.java.programmer > #35003 > unrolled thread

What do you think of my CropImage class

Started byCecil Westerhof <Cecil@decebal.nl>
First post2016-07-20 09:15 +0200
Last post2016-07-21 20:12 +0200
Articles 19 on this page of 59 — 8 participants

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


Contents

  What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-20 09:15 +0200
    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-20 11:12 +0200
    Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-20 10:02 -0700
      Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-20 21:14 +0200
        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-20 12:50 -0700
          Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:11 +0200
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 14:19 +0200
        Re: What do you think of my CropImage class Qu0ll <qu0ll64@gmail.com> - 2016-07-21 05:53 +1000
        Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-20 13:46 -0700
          Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-20 13:59 -0700
            Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-20 15:40 -0700
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:27 +0200
              Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 05:17 -0700
                Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 17:43 +0200
                  Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 08:59 -0700
                    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 19:10 +0200
                      Re: What do you think of my CropImage class Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 21:47 -0400
                        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-25 04:51 -0700
                          Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-25 15:01 -0700
                            Re: What do you think of my CropImage class Arne Vajhøj <arne@vajhoej.dk> - 2016-07-25 21:06 -0400
                          Re: What do you think of my CropImage class Arne Vajhøj <arne@vajhoej.dk> - 2016-07-25 21:09 -0400
              Re: What do you think of my CropImage class Nigel Wade <nmw@local.domain> - 2016-07-21 15:44 +0100
                Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 17:46 +0200
          Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:25 +0200
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 14:16 +0200
      Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 12:05 +0200
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 13:23 +0200
        Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-21 07:58 -0700
          Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 11:13 -0400
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 18:12 +0200
          Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 17:49 +0200
    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 11:58 +0200
      Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 09:35 -0400
        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 09:03 -0700
          Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 12:39 -0400
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 18:07 +0200
          Re: What do you think of my CropImage class Nigel Wade <nmw@local.domain> - 2016-07-21 17:23 +0100
          Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 12:56 -0400
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 19:03 +0200
          Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 10:25 -0700
            Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 14:24 -0400
              Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 11:54 -0700
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 20:25 +0200
              Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 15:37 -0400
                Re: What do you think of my CropImage class Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-21 21:30 +0000
                Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 23:52 +0200
                  Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 20:35 -0400
                    Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-22 04:21 +0200
                      Re: What do you think of my CropImage class Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-21 22:44 -0400
                        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-22 10:27 +0200
                          Re: What do you think of my CropImage class Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-22 10:47 +0000
                        Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-22 05:16 -0700
                          Re: What do you think of my CropImage class Nigel Wade <nmw@local.domain> - 2016-07-22 15:10 +0100
                            Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-22 07:47 -0700
                            Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-22 10:21 -0700
      Re: What do you think of my CropImage class Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-07-21 08:30 -0700
        Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 18:19 +0200
          Re: What do you think of my CropImage class Eric Douglas <e.d.programmer@gmail.com> - 2016-07-21 10:18 -0700
            Re: What do you think of my CropImage class Cecil Westerhof <Cecil@decebal.nl> - 2016-07-21 20:12 +0200

Page 3 of 3 — ← Prev page 1 2 [3]


#35064

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 14:24 -0400
Message-ID<nmr413$a3q$1@dont-email.me>
In reply to#35062
On 7/21/2016 1:25 PM, Eric Douglas wrote:
> On Thursday, July 21, 2016 at 1:14:08 PM UTC-4, Cecil Westerhof wrote:
>>
>
> I never or rarely use pack, though many examples on the web do.  It automatically sets the size and location of your controls based on their size values, the layout, and the other controls on the same pane.  In our application that's irrelevant since we use non-resizeable windows and fixed locations and widths.  The pack values have to do with one of the sizes (each control has getSize(), getPreferredSize(), getMinimumSize(), getMaximumSize()) and whether the control is visible.

     When (non-null) layout managers are in use, pack() causes them all
to do their thing, establishing the positions and sizes of the contents
they manage.  If you're using absolute positioning instead of layout
managers, I suppose pack() can be dispensed with.  ("I suppose," because
I've never been 100% confident that I understand why both pack() and
validate() exist; there may be things going on that I don't know about.)

     ... but I'd use it anyhow, because even if *my* component uses no
layout manager, something I embed in it might.  For example, a JSpinner
has assorted sub-bits and sub-pieces, uses its own layout manager to
size and position them.  I'm not sure what happens if you try to
display a JSpinner that's never been pack()ed; it might well depend on
the look-and-feel in force.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


#35067

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-07-21 11:54 -0700
Message-ID<1cf7e992-a0ff-4f57-a96f-40e8a6e234c9@googlegroups.com>
In reply to#35064
On Thursday, July 21, 2016 at 2:24:43 PM UTC-4, Eric Sosman wrote:
>      When (non-null) layout managers are in use, pack() causes them all
> to do their thing, establishing the positions and sizes of the contents
> they manage.  If you're using absolute positioning instead of layout
> managers, I suppose pack() can be dispensed with.  ("I suppose," because
> I've never been 100% confident that I understand why both pack() and
> validate() exist; there may be things going on that I don't know about.)
> 
>      ... but I'd use it anyhow, because even if *my* component uses no
> layout manager, something I embed in it might.  For example, a JSpinner
> has assorted sub-bits and sub-pieces, uses its own layout manager to
> size and position them.  I'm not sure what happens if you try to
> display a JSpinner that's never been pack()ed; it might well depend on
> the look-and-feel in force.

I use some tricks in my API to get things to work right.  My Swing controls are normally embedded in a window created by a different API (http://documentation.basis.com/BASISHelp/WebHelp/winmethods3/bbjwindow_addwrappedjcomponent.htm) with their absolute positioning.  I wrap each of my controls, adding it to a focus border control which then gets added to their window.  My focus border is a JLabel with some default constructor methods which add a focus listener to highlight the focused control in blue.  I pass each control into the constructor of the focus border which calls setOpaque(false) then setLayout(new GridLayout()), then adds the control to itself, then calls revalidate().

I do also have a JSpinner control which works fine with this.  My custom JSpinner (made to handle integers) has a custom setMaximum method which calls ((NumberFormatter) ((JSpinner.NumberEditor) super.getEditor()).getTextField().getFormatter()).setMaximum(value) then calls it's ((JSpinner.NumberEditor) super.getEditor()).setPreferredSize(dimension) using a hard width and height calculated from String.valueOf(value).length() and the width and height of a character of the current (fixed width) font.

For my standalone test programs I never use JFrame.  I use JDialog for my top levels windows which allows passing a window into another window, disabling the first window until the second window is closed, and also allows removing window decorations as needed.

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


#35066

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 20:25 +0200
Message-ID<87vazy4zm2.fsf@Equus.decebal.nl>
In reply to#35062
On Thursday 21 Jul 2016 19:25 CEST, Eric Douglas wrote:

> On Thursday, July 21, 2016 at 1:14:08 PM UTC-4, Cecil Westerhof wrote:
>>
>
> I never or rarely use pack, though many examples on the web do. It
> automatically sets the size and location of your controls based on
> their size values, the layout, and the other controls on the same
> pane. In our application that's irrelevant since we use
> non-resizeable windows and fixed locations and widths. The pack
> values have to do with one of the sizes (each control has getSize(),
> getPreferredSize(), getMinimumSize(), getMaximumSize()) and whether
> the control is visible.

In this case I think I prefer non re-sizeable also. So I did that
already.

I just have one little problem. At the moment I do:
        crop.setBounds(      10, imageHeight + 10,  80, 30);
        load.setBounds(     110, imageHeight + 10,  80, 30);
        imageInfo.setBounds( 10, imageHeight + 50, 500, 30);
        selectInfo.setBounds(10, imageHeight + 90, 500, 30);
        setSize(imageWidth + 10, imageHeight + 160);

because title and things like that takes room, but I do not know how
much. How can I retrieve these values? Then the application looks a
little better and I do not have to be afraid it will not be OK on
other platforms.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


#35068

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 15:37 -0400
Message-ID<nmr8av$qcu$1@dont-email.me>
In reply to#35066
On 7/21/2016 2:25 PM, Cecil Westerhof wrote:
> [...]
> I just have one little problem. At the moment I do:
>         crop.setBounds(      10, imageHeight + 10,  80, 30);
>         load.setBounds(     110, imageHeight + 10,  80, 30);
>         imageInfo.setBounds( 10, imageHeight + 50, 500, 30);
>         selectInfo.setBounds(10, imageHeight + 90, 500, 30);
>         setSize(imageWidth + 10, imageHeight + 160);
>
> because title and things like that takes room, but I do not know how
> much. How can I retrieve these values? Then the application looks a
> little better and I do not have to be afraid it will not be OK on
> other platforms.

     Possibly useful as a starting point:

	Dimension screenSize =
	    Toolkit.getDefaultToolkit().getScreenSize();

(Disclaimer: I've only used this on single-screen machines; you need
to work harder if there are multiple displays.)


-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


#35072

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2016-07-21 21:30 +0000
Message-ID<nmresv$fnl$1@dont-email.me>
In reply to#35068
On Thu, 21 Jul 2016 15:37:55 -0400, Eric Sosman wrote:

> On 7/21/2016 2:25 PM, Cecil Westerhof wrote:
>> [...]
>> I just have one little problem. At the moment I do:
>>         crop.setBounds(      10, imageHeight + 10,  80, 30);
>>         load.setBounds(     110, imageHeight + 10,  80, 30);
>>         imageInfo.setBounds( 10, imageHeight + 50, 500, 30);
>>         selectInfo.setBounds(10, imageHeight + 90, 500, 30);
>>         setSize(imageWidth + 10, imageHeight + 160);
>>
>> because title and things like that takes room, but I do not know how
>> much. How can I retrieve these values? Then the application looks a
>> little better and I do not have to be afraid it will not be OK on other
>> platforms.
> 
>      Possibly useful as a starting point:
> 
> 	Dimension screenSize =
> 	    Toolkit.getDefaultToolkit().getScreenSize();
> 
> (Disclaimer: I've only used this on single-screen machines; you need to
> work harder if there are multiple displays.)
>
Same here. I specify major component sizes, i.e. JPanel, etc.  as 
percentages of the screen size returned by the Toolkit. The only 
components I specify in pixels are text-related components, where the 
component size determines whether the text gets cropped. I suppose I 
should work back the other way by basing the component size on the size 
and font used by the text it displays, but so far I've hand-tuned this 
and found that it has worked acceptably on different-sized screens, but 
maybe I've just been lucky.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

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


#35074

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 23:52 +0200
Message-ID<87r3am4q2l.fsf@Equus.decebal.nl>
In reply to#35068
On Thursday 21 Jul 2016 21:37 CEST, Eric Sosman wrote:

> On 7/21/2016 2:25 PM, Cecil Westerhof wrote:
>> [...]
>> I just have one little problem. At the moment I do:
>> crop.setBounds(      10, imageHeight + 10,  80, 30);
>> load.setBounds(     110, imageHeight + 10,  80, 30);
>> imageInfo.setBounds( 10, imageHeight + 50, 500, 30);
>> selectInfo.setBounds(10, imageHeight + 90, 500, 30);
>> setSize(imageWidth + 10, imageHeight + 160);
>>
>> because title and things like that takes room, but I do not know
>> how much. How can I retrieve these values? Then the application
>> looks a little better and I do not have to be afraid it will not be
>> OK on other platforms.
>
> Possibly useful as a starting point:
>
> 	Dimension screenSize =
> 	    Toolkit.getDefaultToolkit().getScreenSize();
>
> (Disclaimer: I've only used this on single-screen machines; you need
> to work harder if there are multiple displays.)

That was not what I mend: I had problems with that it seemed I needed
to set the size greater as the combination of what I put in the frame.
But it could be that I made an error. I need to look into it better.
But this has not the highest priority. Is more icing on the cake.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


#35075

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 20:35 -0400
Message-ID<nmrpp8$lfv$1@dont-email.me>
In reply to#35074
On 7/21/2016 5:52 PM, Cecil Westerhof wrote:
> On Thursday 21 Jul 2016 21:37 CEST, Eric Sosman wrote:
>
>> On 7/21/2016 2:25 PM, Cecil Westerhof wrote:
>>> [...]
>>> I just have one little problem. At the moment I do:
>>> crop.setBounds(      10, imageHeight + 10,  80, 30);
>>> load.setBounds(     110, imageHeight + 10,  80, 30);
>>> imageInfo.setBounds( 10, imageHeight + 50, 500, 30);
>>> selectInfo.setBounds(10, imageHeight + 90, 500, 30);
>>> setSize(imageWidth + 10, imageHeight + 160);
>>>
>>> because title and things like that takes room, but I do not know
>>> how much. How can I retrieve these values? Then the application
>>> looks a little better and I do not have to be afraid it will not be
>>> OK on other platforms.
>>
>> Possibly useful as a starting point:
>>
>> 	Dimension screenSize =
>> 	    Toolkit.getDefaultToolkit().getScreenSize();
>>
>> (Disclaimer: I've only used this on single-screen machines; you need
>> to work harder if there are multiple displays.)
>
> That was not what I mend: I had problems with that it seemed I needed
> to set the size greater as the combination of what I put in the frame.
> But it could be that I made an error. I need to look into it better.
> But this has not the highest priority. Is more icing on the cake.

     Okay, I may have misinterpreted your need.  However, it looks to
me as though your difficulty is self-inflicted by your insistence on
using absolute positioning.  If you used a layout manager instead, you'd
just setPreferredSize() on the image-displaying panel (which might well
have a null layout manager), and Swing would figure out the dimensions
of title bars, menu bars, scroll bars, sand bars, stars and bars, and
all the rest.

     But since you want to use absolute positioning, well, ... (Shrug.)

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


#35077

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-22 04:21 +0200
Message-ID<87mvla4dlt.fsf@Equus.decebal.nl>
In reply to#35075
On Friday 22 Jul 2016 02:35 CEST, Eric Sosman wrote:

> Okay, I may have misinterpreted your need. However, it looks to me
> as though your difficulty is self-inflicted by your insistence on
> using absolute positioning. If you used a layout manager instead,
> you'd just setPreferredSize() on the image-displaying panel (which
> might well have a null layout manager), and Swing would figure out
> the dimensions of title bars, menu bars, scroll bars, sand bars,
> stars and bars, and all the rest.
>
> But since you want to use absolute positioning, well, ... (Shrug.)

No, I do not want to use absolute positioning, but without it I did
not get it working. I now use BoxLayout, I am not there yet, but I am
on the right path. I still have a few quirks. I will post those soon.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


#35078

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-07-21 22:44 -0400
Message-ID<nms1aq$6jj$1@dont-email.me>
In reply to#35077
On 7/21/2016 10:21 PM, Cecil Westerhof wrote:
> On Friday 22 Jul 2016 02:35 CEST, Eric Sosman wrote:
>
>> Okay, I may have misinterpreted your need. However, it looks to me
>> as though your difficulty is self-inflicted by your insistence on
>> using absolute positioning. If you used a layout manager instead,
>> you'd just setPreferredSize() on the image-displaying panel (which
>> might well have a null layout manager), and Swing would figure out
>> the dimensions of title bars, menu bars, scroll bars, sand bars,
>> stars and bars, and all the rest.
>>
>> But since you want to use absolute positioning, well, ... (Shrug.)
>
> No, I do not want to use absolute positioning, but without it I did
> not get it working. I now use BoxLayout, I am not there yet, but I am
> on the right path. I still have a few quirks. I will post those soon.

     "Good," I think.  Letting layout managers do their thing relieves
you of worries like "How much room should I leave for borders?" and
"Will the amount of border-room be different on other devices or other
look-and-feel settings?"

     YMMV, but speaking for myself: I've used null layout only with
panels I treat as "canvases" or "drawing surfaces," panels that display
images or vector drawings or other "painted" things as opposed to
"contained components."  I do not recall ever using a null layout on
a top-level container.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


#35080

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-22 10:27 +0200
Message-ID<87invy3wnv.fsf@Equus.decebal.nl>
In reply to#35078
On Friday 22 Jul 2016 04:44 CEST, Eric Sosman wrote:

> On 7/21/2016 10:21 PM, Cecil Westerhof wrote:
>> On Friday 22 Jul 2016 02:35 CEST, Eric Sosman wrote:
>>
>>> Okay, I may have misinterpreted your need. However, it looks to me
>>> as though your difficulty is self-inflicted by your insistence on
>>> using absolute positioning. If you used a layout manager instead,
>>> you'd just setPreferredSize() on the image-displaying panel (which
>>> might well have a null layout manager), and Swing would figure out
>>> the dimensions of title bars, menu bars, scroll bars, sand bars,
>>> stars and bars, and all the rest.
>>>
>>> But since you want to use absolute positioning, well, ... (Shrug.)
>>
>> No, I do not want to use absolute positioning, but without it I did
>> not get it working. I now use BoxLayout, I am not there yet, but I
>> am on the right path. I still have a few quirks. I will post those
>> soon.
>
> "Good," I think. Letting layout managers do their thing relieves you
> of worries like "How much room should I leave for borders?" and
> "Will the amount of border-room be different on other devices or
> other look-and-feel settings?"
>
> YMMV, but speaking for myself: I've used null layout only with
> panels I treat as "canvases" or "drawing surfaces," panels that
> display images or vector drawings or other "painted" things as
> opposed to "contained components." I do not recall ever using a null
> layout on a top-level container.

A null layout did not work, but BoxLayout works not completely.

I have the following code:
    boolean sameLine = false;
    setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
    d.setSize(80, 30);
    crop.setPreferredSize(d);
    load.setPreferredSize(d);
    d.setSize(500, 30);
    imageInfo.setPreferredSize(d);
    selectInfo.setPreferredSize(d);
    add(panel);
    if (sameLine) {
        buttons.setLayout(new FlowLayout());
        buttons.add(crop);
        buttons.add(load);
        add(buttons);
    } else {
        add(crop);
        add(load);
    }
    add(imageInfo);
    add(selectInfo);
    pack();

With sameLine = false I get:
    https://drive.google.com/file/d/0BzW5q7uL-6z0eERBS3B1RE1jZEU/view

There are two things I do not understand:
    - There is a grey area beside the picture.
    - The buttons are not exactly the same length.

But these are minor, so those can wait.

When I change sameline to false I get:
    https://drive.google.com/open?id=0BzW5q7uL-6z0em91OW14VW1Qakk

Here the buttons are on the same line as I want them to be. But there
are two problems:
    - The buttons are made very big. They fill the complete line and
      make it even bigger. I want them have the size of the previous
      one and displayed like in this picture:
          https://drive.google.com/open?id=0BzW5q7uL-6z0XzNJb0FSRFFxMDA
    - imageInfo and selectInfo are moved to the right.

Why is this happening?
I would like the buttons displayed as in the third picture and the
info lines as in the first picture. How would I do that?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


#35081

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2016-07-22 10:47 +0000
Message-ID<nmstkv$fa7$1@dont-email.me>
In reply to#35080
On Fri, 22 Jul 2016 10:27:16 +0200, Cecil Westerhof wrote:

> On Friday 22 Jul 2016 04:44 CEST, Eric Sosman wrote:
> 
>> On 7/21/2016 10:21 PM, Cecil Westerhof wrote:
>>> On Friday 22 Jul 2016 02:35 CEST, Eric Sosman wrote:
>>>
>>>> Okay, I may have misinterpreted your need. However, it looks to me as
>>>> though your difficulty is self-inflicted by your insistence on using
>>>> absolute positioning. If you used a layout manager instead, you'd
>>>> just setPreferredSize() on the image-displaying panel (which might
>>>> well have a null layout manager), and Swing would figure out the
>>>> dimensions of title bars, menu bars, scroll bars, sand bars, stars
>>>> and bars, and all the rest.
>>>>
>>>> But since you want to use absolute positioning, well, ... (Shrug.)
>>>
>>> No, I do not want to use absolute positioning, but without it I did
>>> not get it working. I now use BoxLayout, I am not there yet, but I am
>>> on the right path. I still have a few quirks. I will post those soon.
>>
>> "Good," I think. Letting layout managers do their thing relieves you of
>> worries like "How much room should I leave for borders?" and "Will the
>> amount of border-room be different on other devices or other
>> look-and-feel settings?"
>>
>> YMMV, but speaking for myself: I've used null layout only with panels I
>> treat as "canvases" or "drawing surfaces," panels that display images
>> or vector drawings or other "painted" things as opposed to "contained
>> components." I do not recall ever using a null layout on a top-level
>> container.
> 
> A null layout did not work, but BoxLayout works not completely.
> 
> I have the following code:
>     boolean sameLine = false;
>     setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
>     d.setSize(80, 30);
>     crop.setPreferredSize(d);
>     load.setPreferredSize(d);
>     d.setSize(500, 30);
>     imageInfo.setPreferredSize(d);
>     selectInfo.setPreferredSize(d);
>     add(panel);
>     if (sameLine) {
>         buttons.setLayout(new FlowLayout());
>         buttons.add(crop); buttons.add(load);
>         add(buttons);
>     } else {
>         add(crop);
>         add(load);
>     }
>     add(imageInfo);
>     add(selectInfo);
>     pack();
> 
> With sameLine = false I get:
>     https://drive.google.com/file/d/0BzW5q7uL-6z0eERBS3B1RE1jZEU/view
> 
> There are two things I do not understand:
>     - There is a grey area beside the picture.
>     - The buttons are not exactly the same length.
> 
> But these are minor, so those can wait.
> 
> When I change sameline to false I get:
>     https://drive.google.com/open?id=0BzW5q7uL-6z0em91OW14VW1Qakk
> 
> Here the buttons are on the same line as I want them to be. But there
> are two problems:
>     - The buttons are made very big. They fill the complete line and
>       make it even bigger. I want them have the size of the previous one
>       and displayed like in this picture:
>           https://drive.google.com/open?id=0BzW5q7uL-6z0XzNJb0FSRFFxMDA
>     - imageInfo and selectInfo are moved to the right.
> 
> Why is this happening?
> I would like the buttons displayed as in the third picture and the info
> lines as in the first picture. How would I do that?

This isn't particularly relevant to your cropping project, but if you 
need to build a control panel or some other text oriented panel with 
JLabels, JButtons, JEditorPanes or JTextFields laid out in rows and 
columns, you might find that the se.datadosen.RiverLayout layout manager 
is one of the best suited to this task. I'm really surprised that 
something similar isn't part of the standard JDK. FlowLayout comes close, 
but lacks RiverLayout's tab and linebreak capabilities, which it uses to 
arrange components in left-justified columns and to start new rows of 
components.
 

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

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


#35082

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-07-22 05:16 -0700
Message-ID<38012169-26ac-47b4-91c9-cfbb84d8c042@googlegroups.com>
In reply to#35078
On Thursday, July 21, 2016 at 10:44:50 PM UTC-4, Eric Sosman wrote:
>      "Good," I think.  Letting layout managers do their thing relieves
> you of worries like "How much room should I leave for borders?" and
> "Will the amount of border-room be different on other devices or other
> look-and-feel settings?"
> 
>      YMMV, but speaking for myself: I've used null layout only with
> panels I treat as "canvases" or "drawing surfaces," panels that display
> images or vector drawings or other "painted" things as opposed to
> "contained components."  I do not recall ever using a null layout on
> a top-level container.

I normally use a null layout and give everything an absolute size and position, which seems the easiest thing to do when you have a minimum window size to work with and you don't need resize-able controls.

I tried using a non-null layout once and the only thing I could get to look right with a handful of controls at different sizes and positions was a GroupLayout, though it's a bit complicated to get right.  I've heard this is what NetBeans does.

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


#35086

FromNigel Wade <nmw@local.domain>
Date2016-07-22 15:10 +0100
Message-ID<dvenqbFouupU1@mid.individual.net>
In reply to#35082
On 22/07/16 13:16, Eric Douglas wrote:
> On Thursday, July 21, 2016 at 10:44:50 PM UTC-4, Eric Sosman wrote:
>>       "Good," I think.  Letting layout managers do their thing relieves
>> you of worries like "How much room should I leave for borders?" and
>> "Will the amount of border-room be different on other devices or other
>> look-and-feel settings?"
>>
>>       YMMV, but speaking for myself: I've used null layout only with
>> panels I treat as "canvases" or "drawing surfaces," panels that display
>> images or vector drawings or other "painted" things as opposed to
>> "contained components."  I do not recall ever using a null layout on
>> a top-level container.
>
> I normally use a null layout and give everything an absolute size and position, which seems the easiest thing to do when you have a minimum window size to work with and you don't need resize-able controls.
>

How do you cope with a different display, or a different OS, with different fonts/font metrics, or a display with a different resolution and/or scaling factors? Presumably you have to manually calculate the size of every control, taking into account the insets/margins etc. then the containers, and so on up the hierarchy.


> I tried using a non-null layout once and the only thing I could get to look right with a handful of controls at different sizes and positions was a GroupLayout, though it's a bit complicated to get right.  I've heard this is what NetBeans does.
>

Gridbag and Border are the main layouts I use. There's pretty much nothing I've ever constructed in a GUI which couldn't be managed by a suitable combination of those two layouts. The key to any GUI is not to try to force every component into the same container, and then try to  micro-manage the layout. Instead use multiple containers, containers within containers, each using their own layout, until you get the desired effect.

I do nearly everything in NetBeans/Matisse, only tweaking things by hand where necessary. These are tools which make my life much easier/simpler, so I use them.
Even on the rare occasions where I decide I need to code a GUI by hand I generally run a mock-up in Matisse to get the basic layout, and then copy the components and layout configuration into my custom GUI. It's just so much easier, and quicker, to use NetBeans/Matisse to generate a GUI, and all the associated boiler-plate.

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


#35087

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2016-07-22 07:47 -0700
Message-ID<nmtbmv$47g$1@dont-email.me>
In reply to#35086
On 7/22/2016 07:10, Nigel Wade wrote:
> Gridbag and Border are the main layouts I use. There's pretty much
> nothing I've ever constructed in a GUI which couldn't be managed by a
> suitable combination of those two layouts. The key to any GUI is not to
> try to force every component into the same container, and then try to
> micro-manage the layout. Instead use multiple containers, containers
> within containers, each using their own layout, until you get the
> desired effect.

I do almost everything with GridBagLayout and a couple of things with 
BorderLayout and FlowLayout.  Years ago I wrote a program to demonstrate 
how GridBagLayout works.  Code is below.  I haven't used it in a long 
time but it might be really handy for Cecil.

Cecil there are some sample layouts but you can create your own 
components and constraints to try a piece of a layout to see how the 
components interact.  In the lower right corner is a box that you can 
drag to make the layout area smaller and see what happens when your 
components don't have enough room.

//package com.knutejohnson.demos;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class GridBagTester extends JPanel implements ActionListener {
     private static final String[] colorNames = { "Black","Blue","Cyan",
      "Green","Gray","Magenta","Orange","Pink","Red","Yellow" };
     private static final Color[] colors = { 
Color.BLACK,Color.BLUE,Color.CYAN,
      Color.GREEN,Color.GRAY,Color.MAGENTA,Color.ORANGE,Color.PINK,
      Color.RED,Color.YELLOW };
     private static final String instructionStr =
      "<html><ul>" +
      "<li>Use the 'Edit' menu to select a component by color." +
      "<li>Use the sub-menus to 'Add', 'Remove', set 'Constraints' 
on,<br>" +
      "or set the 'Sizes' of a component." +
      "<li>Right click on a component to popup its menu." +
      "<li>The 'View' menu (not available with JApplet) has options 
to<br>" +
      "pack the frame or set its size." +
      "<li>Click and drag the small box in the lower right corner to<br>" +
      "resize the panel." +
      "</ul></html>";
     private static final String aboutStr =
      "GridBagTester\nWritten by: Knute Johnson\nUpdated 4 Aug 2008";

     private final JPanel[] panels = new JPanel[colors.length];
     private final GridBagLayout gbl;
     private final GridBagConstraints defaultConstraints;

     public final JMenu file,edit,view,samples,help;

     private final JMenu[] panelMenus;
     private final JMenuItem quit,pack,six40x480,clear,instructions,about;
     private final JMenuItem layout1, layout2, layout3;

     private boolean mouseFlag;

     public GridBagTester() {
         setBorder(BorderFactory.createLineBorder(Color.BLACK));

         // create menus for use by top level container
         file = new JMenu("File");
         file.setMnemonic(KeyEvent.VK_F);
         edit = new JMenu("Edit");
         edit.setMnemonic(KeyEvent.VK_E);
         view = new JMenu("View");
         view.setMnemonic(KeyEvent.VK_V);
         samples = new JMenu("Samples");
         samples.setMnemonic(KeyEvent.VK_S);
         help = new JMenu("Help");
         help.setMnemonic(KeyEvent.VK_H);
         quit = new JMenuItem("Quit");
         quit.addActionListener(this);
         file.add(quit);
         pack = new JMenuItem("Pack");
         pack.addActionListener(this);
         view.add(pack);
         six40x480 = new JMenuItem("640x480");
         six40x480.addActionListener(this);
         view.add(six40x480);
         layout1 = new JMenuItem("Layout 1");
         layout1.addActionListener(this);
         samples.add(layout1);
         layout2 = new JMenuItem("Layout 2");
         layout2.addActionListener(this);
         samples.add(layout2);
         layout3 = new JMenuItem("Layout 3");
         layout3.addActionListener(this);
         samples.add(layout3);
         instructions = new JMenuItem("Instructions");
         instructions.addActionListener(this);
         help.add(instructions);
         about = new JMenuItem("About");
         about.addActionListener(this);
         help.add(about);

         panelMenus = new JMenu[colors.length];
         for (int i=0; i<colors.length; i++) {
             panelMenus[i] = new JMenu(colorNames[i]);
             edit.add(panelMenus[i]);
             IndexedJMenuItem mi = new IndexedJMenuItem("Add",i);
             mi.addActionListener(this);
             panelMenus[i].add(mi);
             mi = new IndexedJMenuItem("Remove",i);
             mi.addActionListener(this);
             panelMenus[i].add(mi);
             mi = new IndexedJMenuItem("Constraints",i);
             mi.addActionListener(this);
             panelMenus[i].add(mi);
             mi = new IndexedJMenuItem("Sizes",i);
             mi.addActionListener(this);
             panelMenus[i].add(mi);
         }

         edit.add(new JSeparator());
         clear = new JMenuItem("Clear");
         clear.addActionListener(this);
         edit.add(clear);

         gbl = new GridBagLayout();
         setLayout(gbl);
         defaultConstraints = new GridBagConstraints();

         for (int i=0; i<colors.length; i++) {
             panels[i] = new JPanel(new BorderLayout());
             JLabel l = new JLabel(colorNames[i],JLabel.CENTER);
             l.setForeground(new Color(colors[i].getRGB() ^ 0xafafaf));
             panels[i].add(l,BorderLayout.CENTER);
             panels[i].setBackground(colors[i]);
             panels[i].setPreferredSize(new Dimension(80,60));

             JPopupMenu popup = new JPopupMenu();
             IndexedJMenuItem mi = new IndexedJMenuItem("Remove",i);
             mi.addActionListener(this);
             popup.add(mi);
             mi = new IndexedJMenuItem("Constraints",i);
             mi.addActionListener(this);
             popup.add(mi);
             mi = new IndexedJMenuItem("Sizes",i);
             mi.addActionListener(this);
             popup.add(mi);

             panels[i].addMouseListener(new PopupListener(popup));
         }

         MouseAdapter ma = new MouseAdapter() {
             public void mousePressed(MouseEvent me) {
                 Rectangle r = new 
Rectangle(getWidth()-8,getHeight()-8,8,8);
                 if (r.contains(me.getPoint())) {
                     mouseFlag = true;
                     // this causes cursor to move to center of drag box 
when
                     // mouse is clicked if the box can move
                     MouseEvent event = new MouseEvent(
                      (Component)me.getSource(),
                      MouseEvent.MOUSE_DRAGGED,
                      me.getWhen(),
                      me.getModifiersEx(),
                      me.getX(),
                      me.getY(),
                      me.getClickCount(),
                      me.isPopupTrigger());
                     processMouseMotionEvent(event);
                 }
             }
             public void mouseReleased(MouseEvent me) {
                 mouseFlag = false;
             }
         };

         MouseMotionAdapter mma = new MouseMotionAdapter() {
             public void mouseMoved(MouseEvent me) {
                 Rectangle r = new 
Rectangle(getWidth()-8,getHeight()-8,8,8);
                 if (r.contains(me.getPoint()))
                     setCursor(Cursor.getPredefinedCursor(
                      Cursor.CROSSHAIR_CURSOR));
                 else
                     setCursor(Cursor.getDefaultCursor());
             }
             public void mouseDragged(MouseEvent me) {
                 if (mouseFlag) {
                     Container cont = getTopLevelAncestor();
                     if (cont instanceof JApplet)
                         cont = ((JApplet)cont).getContentPane();
                     else if (cont instanceof JFrame)
                         cont = ((JFrame)cont).getContentPane();
                     else
                         return;
                     int x = me.getX();
                     if (x < 4)
                         x = 4;
                     int y = me.getY();
                     if (y < 4)
                         y = 4;
                     if (x > cont.getWidth() - 5)
                         x = cont.getWidth() - 5;
                     if (y > cont.getHeight() - 5)
                         y = cont.getHeight() - 5;

                     setSize(x + 5,y + 5);
                     validate();
                 }
             }
         };
         addMouseListener(ma);
         addMouseMotionListener(mma);
     }

     public void paintComponent(Graphics g) {
         super.paintComponent(g);
         g.drawRect(getWidth()-9,getHeight()-9,8,8);
     }

     public void actionPerformed(ActionEvent ae) {
         String ac = ae.getActionCommand();

         if (ac.equals("Quit"))
             System.exit(0);
         else if (ac.equals("Pack")) {
             Container cont = getTopLevelAncestor();
             if (cont instanceof JFrame)
                 ((JFrame)cont).pack();
         } else if (ac.equals("640x480")) {
             Container cont = getTopLevelAncestor();
             if (cont instanceof JFrame)
                 ((JFrame)cont).setSize(640,480);
         } else if (ac.equals("Clear")) {
             removeAll();
             validate();
             repaint();
         } else if (ac.equals("Instructions")) {
             JOptionPane.showMessageDialog(this,instructionStr);
         } else if (ac.equals("About")) {
             JOptionPane.showMessageDialog(this,aboutStr);
         } else if (ac.equals("Layout 1")) {
             removeAll();

             // reset preferred size
             for (int i=0; i<4; i++)
                 panels[i].setPreferredSize(new Dimension(80,60));

             GridBagConstraints c = new GridBagConstraints();
             c.gridx = 0;

             add(panels[0],c);

             c.gridx = 1;
             add(panels[1],c);

             c.gridx = 2;
             add(panels[2],c);

             c.gridx = 0;  c.gridwidth = 3;  c.ipady = 40;
             c.fill = GridBagConstraints.HORIZONTAL;
             add(panels[3],c);

             c.gridx = 1;  c.gridwidth = 2;  c.ipady = -20; 
c.insets.top = 10;
             add(panels[4],c);

             validate();
             repaint();
         } else if (ac.equals("Layout 2")) {
             removeAll();

             // reset preferred size
             for (int i=0; i<4; i++)
                 panels[i].setPreferredSize(new Dimension(80,60));

             GridBagConstraints c = new GridBagConstraints();
             c.gridx = c.gridy = 0;  c.weightx = c.weighty = 1.0;

             c.anchor = GridBagConstraints.NORTHWEST;
             add(panels[0],c);

             c.gridx = 2;  c.anchor = GridBagConstraints.NORTHEAST;
             add(panels[1],c);

             c.gridx = c.gridy = 1;  c.anchor = GridBagConstraints.CENTER;
             add(panels[2],c);

             c.gridx = 0;  c.gridy = 2;  c.anchor = 
GridBagConstraints.SOUTHWEST;
             add(panels[3],c);

             c.gridx = 2;  c.anchor = GridBagConstraints.SOUTHEAST;
             add(panels[4],c);

             validate();
             repaint();
         } else if (ac.equals("Layout 3")) {
             removeAll();

             // reset preferred size
             for (int i=0; i<4; i++)
                 panels[i].setPreferredSize(new Dimension(80,60));

             GridBagConstraints c = new GridBagConstraints();
             c.gridx =0;  c.gridy = GridBagConstraints.RELATIVE;
             c.weightx = c.weighty = 1.0;

             c.anchor = GridBagConstraints.NORTH;
             add(panels[0],c);

             c.anchor = GridBagConstraints.SOUTH;
             add(panels[1],c);

             c.anchor = GridBagConstraints.NORTH;
             add(panels[2],c);

             c.anchor = GridBagConstraints.SOUTH;
             add(panels[3],c);

             validate();
             repaint();
         }

         if (ae.getSource() instanceof IndexedJMenuItem) {
             int menuIndex = ((IndexedJMenuItem)ae.getSource()).getIndex();

             if (ac.equals("Add")) {
                 if (!panels[menuIndex].isDisplayable()) {
                     add(panels[menuIndex],defaultConstraints);
                     validate();
                     repaint();
                 }
             } else if (ac.equals("Remove")) {
                 if (panels[menuIndex].isDisplayable()) {
                     remove(panels[menuIndex]);
                     validate();
                     repaint();
                 }
             } else if (ac.equals("Constraints")) {
                 GridBagConstraints c = ConstraintsDialog.show(
                  panels[menuIndex],colorNames[menuIndex],
                  gbl.getConstraints(panels[menuIndex]));
                 if (c != null) {
                     gbl.setConstraints(panels[menuIndex],c);
                     panels[menuIndex].revalidate();
                 }
             } else if (ac.equals("Sizes")) {
                 Dimension[] dim = SizesDialog.show(panels[menuIndex],
                  colorNames[menuIndex],panels[menuIndex].getMinimumSize(),
                  panels[menuIndex].getPreferredSize(),
                  panels[menuIndex].getMaximumSize());
                 if (dim != null) {
                     panels[menuIndex].setMinimumSize(dim[0]);
                     panels[menuIndex].setPreferredSize(dim[1]);
                     panels[menuIndex].setMaximumSize(dim[2]);
                     panels[menuIndex].revalidate();
                 }
             }
         }
     }

     static class IndexedJMenuItem extends JMenuItem {
         private final int index;

         public IndexedJMenuItem(String text, int index) {
             super(text);
             this.index = index;
         }

         public int getIndex() {
             return index;
         }
     }

     static class PopupListener extends MouseAdapter {
         private final JPopupMenu popup;

         public PopupListener(JPopupMenu popup) {
             this.popup = popup;
         }

         public void mousePressed(MouseEvent me) {
             if (me.isPopupTrigger())
                 popup.show(me.getComponent(),me.getX(),me.getY());
         }

         public void mouseReleased(MouseEvent me) {
             if (me.isPopupTrigger())
                 popup.show(me.getComponent(),me.getX(),me.getY());
         }
     }

     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
                 JFrame f = new JFrame("GridBagTester");
                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 GridBagTester gbt = new GridBagTester();
                 f.getContentPane().add(gbt);

                 JMenuBar mb = new JMenuBar();
                 f.setJMenuBar(mb);
                 mb.add(gbt.file);
                 mb.add(gbt.edit);
                 mb.add(gbt.view);
                 mb.add(gbt.samples);
                 mb.add(gbt.help);

                 f.setSize(640,480);
                 f.setVisible(true);
             }
         });
     }
}


//package com.knutejohnson.demos;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SizesDialog extends JDialog implements ActionListener {
     private JTextField minimumWidth, minimumHeight;
     private JTextField preferredWidth, preferredHeight;
     private JTextField maximumWidth, maximumHeight;
     private JButton updateButton, cancelButton;

     private boolean flag;

     public SizesDialog(String title) {
         super((Dialog)null,title,true);

         Container cp = getContentPane();

         addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent we) {
                 setVisible(false);
             }
         });

         setLayout(new GridBagLayout());
         GridBagConstraints c = new GridBagConstraints();
         c.insets = new Insets(2,2,2,2);

         c.gridx = 1;  c.gridy = 0;
         cp.add(new JLabel("Width"),c);

         ++c.gridx;
         cp.add(new JLabel("Height"),c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("minimumSize"),c);

         ++c.gridx;
         minimumWidth = new JTextField(5);
         cp.add(minimumWidth,c);

         ++c.gridx;
         minimumHeight = new JTextField(5);
         cp.add(minimumHeight,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("preferredSize"),c);

         ++c.gridx;
         preferredWidth = new JTextField(5);
         cp.add(preferredWidth,c);

         ++c.gridx;
         preferredHeight = new JTextField(5);
         cp.add(preferredHeight,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("maximumSize"),c);

         ++c.gridx;
         maximumWidth = new JTextField(5);
         cp.add(maximumWidth,c);

         ++c.gridx;
         maximumHeight = new JTextField(5);
         cp.add(maximumHeight,c);

         c.gridx = 0;  ++c.gridy;  c.gridwidth = 3;
         JPanel p = new JPanel(new FlowLayout());
         updateButton = new JButton("Update");
         getRootPane().setDefaultButton(updateButton);
         updateButton.addActionListener(this);
         p.add(updateButton);
         cancelButton = new JButton("Cancel");
         cancelButton.addActionListener(this);
         p.add(cancelButton);
         cp.add(p,c);
     }

     public void actionPerformed(ActionEvent ae) {
         String ac = ae.getActionCommand();

         if (ac.equals("Update")) {
             if (validateFields()) {
                 flag = true;
                 setVisible(false);
             }
         } else if (ac.equals("Cancel")) {
             setVisible(false);
         }
     }

     public boolean validateFields() {
         boolean retcod = true;

         try {
             int n = 0;
             try {
                 minimumWidth.requestFocusInWindow();
                 n = Integer.parseInt(minimumWidth.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("minimumWidth");
             }
             if (n < 0)
                 throw new NumberFormatException("minimumWidth < 0");

             try {
                 minimumHeight.requestFocusInWindow();
                 n = Integer.parseInt(minimumHeight.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("minimumHeight");
             }
             if (n < 0)
                 throw new NumberFormatException("minimumHeight < 0");

             try {
                 preferredWidth.requestFocusInWindow();
                 n = Integer.parseInt(preferredWidth.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("preferredWidth");
             }
             if (n < 0)
                 throw new NumberFormatException("preferredWidth < 0");

             try {
                 preferredHeight.requestFocusInWindow();
                 n = Integer.parseInt(preferredHeight.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("preferredHeight");
             }
             if (n < 0)
                 throw new NumberFormatException("preferredHeight < 0");

             try {
                 maximumWidth.requestFocusInWindow();
                 n = Integer.parseInt(maximumWidth.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("maximumWidth");
             }
             if (n < 0)
                 throw new NumberFormatException("maximumWidth < 0");

             try {
                 maximumHeight.requestFocusInWindow();
                 n = Integer.parseInt(maximumHeight.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("maximumHeight");
             }
             if (n < 0)
                 throw new NumberFormatException("maximumHeight < 0");

         } catch (NumberFormatException nfe) {
             retcod = false;
             JOptionPane.showMessageDialog(SizesDialog.this,nfe,
              "Invalid Data Error!",JOptionPane.ERROR_MESSAGE);
         }

         return retcod;
     }

     public void fillFields(Dimension min, Dimension pref, Dimension max) {
         minimumWidth.setText(Integer.toString(min.width));
         minimumHeight.setText(Integer.toString(min.height));
         preferredWidth.setText(Integer.toString(pref.width));
         preferredHeight.setText(Integer.toString(pref.height));
         maximumWidth.setText(Integer.toString(max.width));
         maximumHeight.setText(Integer.toString(max.height));
     }

     public Dimension[] emptyFields() {
         Dimension[] dim = new Dimension[3];
         dim[0] = new Dimension();
         dim[1] = new Dimension();
         dim[2] = new Dimension();

         try {
             dim[0].width = Integer.parseInt(minimumWidth.getText());
             dim[0].height = Integer.parseInt(minimumHeight.getText());
             dim[1].width = Integer.parseInt(preferredWidth.getText());
             dim[1].height = Integer.parseInt(preferredHeight.getText());
             dim[2].width = Integer.parseInt(maximumWidth.getText());
             dim[2].height = Integer.parseInt(maximumHeight.getText());
         } catch (NumberFormatException nfe) {
             flag = false;
         }

         return dim;
     }

     public static Dimension[] show(Component comp, String title, 
Dimension min,
      Dimension pref, Dimension max) {
         SizesDialog dialog = new SizesDialog(title);
         dialog.fillFields(min,pref,max);
         dialog.pack();
         dialog.setLocationRelativeTo(comp);
         dialog.setVisible(true);
         dialog.dispose();

         return dialog.flag ? dialog.emptyFields() : null;
     }
}


//package com.knutejohnson.demos;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ConstraintsDialog extends JDialog implements ActionListener {
     final String[] gridXYChoices =
      { "RELATIVE","0","1","2","3","4","5","6","7","8","9","10" };
     final String[] gridWHChoices =
      { "REMAINDER","RELATIVE","1","2","3","4","5","6","7","8","9","10" };
     final String[] anchorChoices = { "CENTER","NORTH","NORTHEAST","EAST",
      "SOUTHEAST","SOUTH","SOUTHWEST","WEST","NORTHWEST" };
     final String[] fillChoices = { "NONE","HORIZONTAL","VERTICAL","BOTH" };
     final String[] insetsTip = { "Top","Left","Bottom","Right" } ;

     final JComboBox gridx, gridy, gridwidth, gridheight, fill, anchor;
     final JTextField weightx, weighty, insets[], ipadx, ipady;
     final JButton updateButton, cancelButton;

     private boolean flag;

     public ConstraintsDialog(String title) {
         super((Dialog)null,title,true);

         Container cp = getContentPane();

         addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent we) {
                 setVisible(false);
             }
         });

         setLayout(new GridBagLayout());
         GridBagConstraints c = new GridBagConstraints();
         c.insets = new Insets(2,2,2,2);
         c.weightx = 1.0;
         c.fill = GridBagConstraints.HORIZONTAL;

         c.gridx = 0;  c.gridy = 0;
         cp.add(new JLabel("gridx"),c);

         ++c.gridx;
         gridx = new JComboBox(gridXYChoices);
         cp.add(gridx,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("gridy"),c);

         ++c.gridx;
         gridy = new JComboBox(gridXYChoices);
         cp.add(gridy,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("gridwidth"),c);

         ++c.gridx;
         gridwidth = new JComboBox(gridWHChoices);
         cp.add(gridwidth,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("gridheight"),c);

         ++c.gridx;
         gridheight = new JComboBox(gridWHChoices);
         cp.add(gridheight,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("weightx"),c);

         ++c.gridx;
         weightx = new JTextField(4);
         cp.add(weightx,c);

         c.gridx = 0;  ++c.gridy;
         cp.add(new JLabel("weighty"),c);

         ++c.gridx;
         weighty = new JTextField(4);
         cp.add(weighty,c);

         c.gridx = 2;  c.gridy = 0;
         cp.add(new JLabel("anchor"),c);

         ++c.gridx;
         anchor = new JComboBox(anchorChoices);
         cp.add(anchor,c);

         c.gridx = 2;  ++c.gridy;
         cp.add(new JLabel("fill"),c);

         ++c.gridx;
         fill = new JComboBox(fillChoices);
         cp.add(fill,c);

         c.gridx = 2;  ++c.gridy;
         cp.add(new JLabel("insets"),c);

         ++c.gridx;
         JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
         insets = new JTextField[4];
         for (int i=0; i<insets.length; i++) {
             insets[i] = new JTextField(2);
             insets[i].setToolTipText(insetsTip[i]);
             p.add(insets[i]);
         }
         cp.add(p,c);

         c.gridx = 2;  ++c.gridy;
         cp.add(new JLabel("ipadx"),c);

         ++c.gridx;
         ipadx = new JTextField(4);
         cp.add(ipadx,c);

         c.gridx = 2;  ++c.gridy;
         cp.add(new JLabel("ipady"),c);

         ++c.gridx;
         ipady = new JTextField(4);
         cp.add(ipady,c);

         c.gridx = 0;  c.gridy += 2;  c.gridwidth = 2;
         c.fill = GridBagConstraints.NONE;
         c.anchor = GridBagConstraints.EAST;
         updateButton = new JButton("Update");
         updateButton.addActionListener(this);
         getRootPane().setDefaultButton(updateButton);
         cp.add(updateButton,c);

         c.gridx = 2;
         c.anchor = GridBagConstraints.WEST;
         cancelButton = new JButton("Cancel");
         cancelButton.addActionListener(this);
         cp.add(cancelButton,c);
     }

     public void actionPerformed(ActionEvent ae) {
         String ac = ae.getActionCommand();

         if (ac.equals("Update")) {
             if (validateFields()) {
                 flag = true;
                 setVisible(false);
             }
         } else if (ac.equals("Cancel"))
             setVisible(false);
     }

     public boolean validateFields() {
         boolean retcod = true;

         try {
             double w = 0.0;
             try {
                 weightx.requestFocusInWindow();
                 w = Double.parseDouble(weightx.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("weightx");
             }
             if (w < 0.0)
                 throw new NumberFormatException("weightx < 0.0");

             try {
                 weighty.requestFocusInWindow();
                 w = Double.parseDouble(weighty.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("weighty");
             }
             if (w < 0.0)
                 throw new NumberFormatException("weighty < 0.0");

             int n[] = new int[insets.length];
             try {
                 for (int i=0; i<insets.length; i++) {
                     insets[i].requestFocusInWindow();
                     n[i] = Integer.parseInt(insets[i].getText());
                 }
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("insets");
             }
             for (int i=0; i<insets.length; i++) {
                 if (n[i] < 0) {
                     insets[i].requestFocusInWindow();
                     throw new NumberFormatException("inset < 0");
                 }
             }

             int i = 0;
             try {
                 ipadx.requestFocusInWindow();
                 i = Integer.parseInt(ipadx.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("ipadx");
             }

             try {
                 ipady.requestFocusInWindow();
                 i = Integer.parseInt(ipady.getText());
             } catch (NumberFormatException nfe) {
                 throw new NumberFormatException("ipady");
             }

         } catch (NumberFormatException nfe) {
             retcod = false;
             JOptionPane.showMessageDialog(ConstraintsDialog.this,nfe,
              "Invalid Data Error!",JOptionPane.ERROR_MESSAGE);
         }

         return retcod;
     }

     public void fillFields(GridBagConstraints constraints) {
         if (constraints.gridx == GridBagConstraints.RELATIVE)
             gridx.setSelectedItem("RELATIVE");
         else
             gridx.setSelectedItem(Integer.toString(constraints.gridx));

         if (constraints.gridy == GridBagConstraints.RELATIVE)
             gridy.setSelectedItem("RELATIVE");
         else
             gridy.setSelectedItem(Integer.toString(constraints.gridy));


         if (constraints.gridwidth == GridBagConstraints.RELATIVE)
             gridwidth.setSelectedItem("RELATIVE");
         else if (constraints.gridwidth == GridBagConstraints.REMAINDER)
             gridwidth.setSelectedItem("REMAINDER");
         else
 
gridwidth.setSelectedItem(Integer.toString(constraints.gridwidth));


         if (constraints.gridheight == GridBagConstraints.RELATIVE)
             gridheight.setSelectedItem("RELATIVE");
         else if (constraints.gridheight == GridBagConstraints.REMAINDER)
             gridheight.setSelectedItem("REMAINDER");
         else
             gridheight.setSelectedItem(
              Integer.toString(constraints.gridheight));

         weightx.setText(Double.toString(constraints.weightx));

         weighty.setText(Double.toString(constraints.weighty));

         switch (constraints.anchor) {
             case GridBagConstraints.CENTER:
                 anchor.setSelectedItem("CENTER");  break;
             case GridBagConstraints.NORTH:
                 anchor.setSelectedItem("NORTH");  break;
             case GridBagConstraints.NORTHEAST:
                 anchor.setSelectedItem("NORTHEAST");  break;
             case GridBagConstraints.EAST:
                 anchor.setSelectedItem("EAST");  break;
             case GridBagConstraints.SOUTHEAST:
                 anchor.setSelectedItem("SOUTHEAST");  break;
             case GridBagConstraints.SOUTH:
                 anchor.setSelectedItem("SOUTH");  break;
             case GridBagConstraints.SOUTHWEST:
                 anchor.setSelectedItem("SOUTHWEST");  break;
             case GridBagConstraints.WEST:
                 anchor.setSelectedItem("WEST");  break;
             case GridBagConstraints.NORTHWEST:
                 anchor.setSelectedItem("NORTHWEST");  break;
             default:  break;
         }

         switch (constraints.fill) {
             case GridBagConstraints.NONE:
                 fill.setSelectedItem("NONE");  break;
             case GridBagConstraints.HORIZONTAL:
                 fill.setSelectedItem("HORIZONTAL");  break;
             case GridBagConstraints.VERTICAL:
                 fill.setSelectedItem("VERTICAL");  break;
             case GridBagConstraints.BOTH:
                 fill.setSelectedItem("BOTH");  break;
             default:  break;
         }

         insets[0].setText(Integer.toString(constraints.insets.top));
         insets[1].setText(Integer.toString(constraints.insets.left));
         insets[2].setText(Integer.toString(constraints.insets.bottom));
         insets[3].setText(Integer.toString(constraints.insets.right));

         ipadx.setText(Integer.toString(constraints.ipadx));

         ipady.setText(Integer.toString(constraints.ipady));
     }

     public GridBagConstraints emptyFields() {
         GridBagConstraints constraints = new GridBagConstraints();

         try {
             String str = (String)gridx.getSelectedItem();
             if (str.equals("RELATIVE"))
                 constraints.gridx = GridBagConstraints.RELATIVE;
             else
                 constraints.gridx = Integer.parseInt(str);

             str = (String)gridy.getSelectedItem();
             if (str.equals("RELATIVE"))
                 constraints.gridy = GridBagConstraints.RELATIVE;
             else
                 constraints.gridy = Integer.parseInt(str);

             str = (String)gridwidth.getSelectedItem();
             if (str.equals("REMAINDER"))
                 constraints.gridwidth = GridBagConstraints.REMAINDER;
             else if (str.equals("RELATIVE"))
                 constraints.gridwidth = GridBagConstraints.RELATIVE;
             else
                 constraints.gridwidth = Integer.parseInt(str);

             str = (String)gridheight.getSelectedItem();
             if (str.equals("REMAINDER"))
                 constraints.gridheight = GridBagConstraints.REMAINDER;
             else if (str.equals("RELATIVE"))
                 constraints.gridheight = GridBagConstraints.RELATIVE;
             else
                 constraints.gridheight = Integer.parseInt(str);

             constraints.weightx = 
Double.parseDouble((String)weightx.getText());

             constraints.weighty = 
Double.parseDouble((String)weighty.getText());

             str = (String)anchor.getSelectedItem();
             if (str.equals("CENTER"))
                 constraints.anchor = GridBagConstraints.CENTER;
             else if (str.equals("NORTH"))
                 constraints.anchor = GridBagConstraints.NORTH;
             else if (str.equals("NORTHEAST"))
                 constraints.anchor = GridBagConstraints.NORTHEAST;
             else if (str.equals("EAST"))
                 constraints.anchor = GridBagConstraints.EAST;
             else if (str.equals("SOUTHEAST"))
                 constraints.anchor = GridBagConstraints.SOUTHEAST;
             else if (str.equals("SOUTH"))
                 constraints.anchor = GridBagConstraints.SOUTH;
             else if (str.equals("SOUTHWEST"))
                 constraints.anchor = GridBagConstraints.SOUTHWEST;
             else if (str.equals("WEST"))
                 constraints.anchor = GridBagConstraints.WEST;
             else if (str.equals("NORTHWEST"))
                 constraints.anchor = GridBagConstraints.NORTHWEST;

             str = (String)fill.getSelectedItem();
             if (str.equals("NONE"))
                 constraints.fill = GridBagConstraints.NONE;
             else if (str.equals("HORIZONTAL"))
                 constraints.fill = GridBagConstraints.HORIZONTAL;
             else if (str.equals("VERTICAL"))
                 constraints.fill = GridBagConstraints.VERTICAL;
             else if (str.equals("BOTH"))
                 constraints.fill = GridBagConstraints.BOTH;

             int[] in = new int[insets.length];
             for (int i=0; i<insets.length; i++)
                 in[i] = Integer.parseInt(insets[i].getText());
             constraints.insets = new Insets(in[0],in[1],in[2],in[3]);

             constraints.ipadx = Integer.parseInt((String)ipadx.getText());

             constraints.ipady = Integer.parseInt((String)ipady.getText());
         } catch (NumberFormatException nfe) {
             flag = false;
         }

         return constraints;
     }

     public static GridBagConstraints show(Component comp, String title,
      GridBagConstraints constraints) {
         ConstraintsDialog dialog = new ConstraintsDialog(title);
         dialog.fillFields(constraints);
         dialog.pack();
         dialog.setLocationRelativeTo(comp);
         dialog.setVisible(true);
         dialog.dispose();

         return dialog.flag ? dialog.emptyFields() : null;
     }
}



-- 

Knute Johnson

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


#35089

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-07-22 10:21 -0700
Message-ID<2263d8c0-c406-4e50-830d-3f82ea423fc7@googlegroups.com>
In reply to#35086
On Friday, July 22, 2016 at 10:10:29 AM UTC-4, Nigel Wade wrote:
> How do you cope with a different display, or a different OS, with different fonts/font metrics, or a display with a different resolution and/or scaling factors? Presumably you have to manually calculate the size of every control, taking into account the insets/margins etc. then the containers, and so on up the hierarchy.


Different display?  The app assumes every display has at least 1024x600 resolution if that's what you mean.  Different OS?  We run Windows 8.1 and everything looks the same as it did on XP.  I believe it looks the same on a Mac, don't normally have to worry about that stuff for an in house app.  There are no different fonts.  I use one set of fonts for my app, with the font files embedded in the jar.  Yes size and positions are manual, haven't seen any scaling issues.

> > I tried using a non-null layout once and the only thing I could get to look right with a handful of controls at different sizes and positions was a GroupLayout, though it's a bit complicated to get right.  I've heard this is what NetBeans does.
> >
> 
> Gridbag and Border are the main layouts I use. There's pretty much nothing I've ever constructed in a GUI which couldn't be managed by a suitable combination of those two layouts. The key to any GUI is not to try to force every component into the same container, and then try to  micro-manage the layout. Instead use multiple containers, containers within containers, each using their own layout, until you get the desired effect.

That would be the only alternative I could see, which sounds similar to what the GroupLayout does, if you could use a standard simpler layout like GridLayout and fill it with panels that have their own layouts if you can just divide and subdivide the whole screen until you get there.

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


#35047

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2016-07-21 08:30 -0700
Message-ID<nmqprk$4pv$1@dont-email.me>
In reply to#35042
I think Eric is right about why you are getting the flicker and other 
issues.  That event dispatch thread is very important and mixing AWT and 
Swing components is usually problematic.

I'm thinking you could have a menu of box sizes and select one to crop 
your image.  Here is CropComponent rewritten and cleaned up a bit to use 
a fixed size box instead of the usual mouse dragged variable box.


import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;

public class CropComponent2 extends JPanel {
     BufferedImage bi;
     boolean mouseDown;
     int mouseX,mouseY;

     public CropComponent2(BufferedImage bi) {
         this.bi = bi;
         setPreferredSize(new Dimension(bi.getWidth(),bi.getHeight()));
         addMouseListener(new MouseAdapter() {
             public void mousePressed(MouseEvent me) {
                 mouseDown = true;
                 mouseX = me.getX();
                 mouseY = me.getY();
                 if (mouseX < 50)
                     mouseX = 50;
                 if (mouseX > bi.getWidth() - 50)
                     mouseX = bi.getWidth() - 50;
                 if (mouseY < 50)
                     mouseY = 50;
                 if (mouseY > bi.getHeight() - 50)
                     mouseY = bi.getHeight() - 50;
                 repaint();
             }
             public void mouseReleased(MouseEvent me) {
                 mouseDown = false;
                 BufferedImage subImage =
                  bi.getSubimage(mouseX-50,mouseY-50,100,100);
                 Runnable r = new Runnable() {
                     public void run() {
                         try {
                             ImageIO.write(subImage,"JPEG",new 
File("crop.jpg"));
                         } catch (IOException ioe) {
                             ioe.printStackTrace();
                         }
                     }
                 };
                 new Thread(r).start();
                 repaint();
             }
         });
         addMouseMotionListener(new MouseMotionAdapter() {
             public void mouseDragged(MouseEvent me) {
                 mouseX = me.getX();
                 mouseY = me.getY();
                 if (mouseX < 50)
                     mouseX = 50;
                 if (mouseX > bi.getWidth() - 50)
                     mouseX = bi.getWidth() - 50;
                 if (mouseY < 50)
                     mouseY = 50;
                 if (mouseY > bi.getHeight() - 50)
                     mouseY = bi.getHeight() - 50;
                 repaint();
             }
         });
     }

     public void paintComponent(Graphics g2D) {
         Graphics2D g = (Graphics2D)g2D;
         g.drawImage(bi,0,0,null);
         if (mouseDown) {
             g.setStroke(new BasicStroke(1.0f,BasicStroke.CAP_SQUARE,
              BasicStroke.JOIN_ROUND,1.0f,new float[] {2.0f,3.0f},1.0f));
             g.setColor(Color.WHITE);
             g.drawRect(mouseX-50,mouseY-50,100,100);
         }
     }

     public static void main(final String[] args) {
         EventQueue.invokeLater(() -> {
             try {
                 BufferedImage bi;
                 try {
                     bi = ImageIO.read(new URL(args[0]));
                 } catch (MalformedURLException murle) {
                     bi = ImageIO.read(new File(args[0]));
                 }
                 JFrame f = new JFrame();
                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 CropComponent2 cc = new CropComponent2(bi);
                 JScrollPane sp = new JScrollPane(cc);
                 f.add(sp,BorderLayout.CENTER);
                 f.pack();
                 f.setVisible(true);
             } catch (IOException ioe) {
                 ioe.printStackTrace();
             }
         });
     }
}




-- 

Knute Johnson

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


#35057

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 18:19 +0200
Message-ID<87d1m755gf.fsf@Equus.decebal.nl>
In reply to#35047
On Thursday 21 Jul 2016 17:30 CEST, Knute Johnson wrote:

> I think Eric is right about why you are getting the flicker and
> other issues. That event dispatch thread is very important and
> mixing AWT and Swing components is usually problematic.

The flicker issue is solved. Do I understand it correctly that when a
class (for the GUI) does not start with a J it is an AWT component and
I should not use it?


> I'm thinking you could have a menu of box sizes and select one to
> crop your image.

That is where I want to go to, yes. But before trying that I should
make sure that I need them. Now I know I need them.


> Here is CropComponent rewritten and cleaned up a
> bit to use a fixed size box instead of the usual mouse dragged
> variable box.

I am going to look into that.


You and the rest: thank very much for the help.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


#35061

FromEric Douglas <e.d.programmer@gmail.com>
Date2016-07-21 10:18 -0700
Message-ID<db295eee-4129-4d16-a157-a1509ffa230c@googlegroups.com>
In reply to#35057
On Thursday, July 21, 2016 at 12:44:07 PM UTC-4, Cecil Westerhof wrote:
> The flicker issue is solved. Do I understand it correctly that when a
> class (for the GUI) does not start with a J it is an AWT component and
> I should not use it?

You can extend a Panel directly in a Swing app but to do it properly gets ugly.  It is always best to use a JComponent, and override paintComponent(), not paint().

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


#35063

FromCecil Westerhof <Cecil@decebal.nl>
Date2016-07-21 20:12 +0200
Message-ID<87zipa508k.fsf@Equus.decebal.nl>
In reply to#35061
On Thursday 21 Jul 2016 19:18 CEST, Eric Douglas wrote:

> On Thursday, July 21, 2016 at 12:44:07 PM UTC-4, Cecil Westerhof wrote:
>> The flicker issue is solved. Do I understand it correctly that when
>> a class (for the GUI) does not start with a J it is an AWT
>> component and I should not use it?
>
> You can extend a Panel directly in a Swing app but to do it properly
> gets ugly. It is always best to use a JComponent, and override
> paintComponent(), not paint().

That is what I am doing now.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

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


csiph-web