RFR: 8316146: Open some swing tests 4 [v3]
Alexey Ivanov
aivanov at openjdk.org
Thu Sep 28 17:13:34 UTC 2023
On Thu, 28 Sep 2023 16:05:41 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:
>> test/jdk/javax/swing/ToolTipManager/bug5078214.java line 147:
>>
>>> 145: });
>>> 146:
>>> 147: }
>>
>> As I said, there's absolutely no reason to call `GraphicsEnvironment` methods on EDT — these are not Swing components.
>>
>> There's no reason to store any of these as static fields, they are local variables.
>>
>> Suggestion:
>>
>> private static GraphicsConfiguration getGraphicsConfig() {
>> GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment()
>> .getScreenDevices();
>> for (GraphicsDevice device : devices) {
>> GraphicsConfiguration[] gc = device.getConfigurations();
>> for (int i = 0; i < gc.length; i++) {
>> insets = Toolkit.getDefaultToolkit().getScreenInsets(gc[i]);
>> if (insets.bottom != 0) {
>> return gc[i];
>> }
>> }
>> }
>> return null;
>> }
>>
>>
>> You call this function from the `main` method.
>
> The nested loop could also be enhanced for:
>
> for (GraphicsConfiguration config : device.getConfigurations()) {
> insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
> if (insets.bottom != 0) {
> return config;
> }
> }
And [I still have the concern](https://github.com/openjdk/jdk/pull/15875#discussion_r1335795417) about iterating over all the configurations. It hasn't been addressed.
Since the configuration is not set, I think the inner loop is not needed at all, it should be replaced with
```java
GraphicsConfiguration config = device.getDefaultConfiguration();
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15875#discussion_r1340386748
More information about the client-libs-dev
mailing list