Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Showing lean windows makes them tiny

Open
#278 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java
Domain
desktop, testing

Research direction

Run the supplied RobotTest regression case first, then read org.assertj.swing.monitor.WindowStatus#makeLargeEnoughToReceiveEvents and its shouldResize() logic. Done means showWindow leaves a packed window taller than its title-bar inset instead of shrinking it to MINIMUM_WINDOW_SIZE, and the regression test passes.

Written by the indexing model from the issue text.

Description

If a Window has little content, AssertJ makes the window even smaller.

Here's a failing test:

import org.assertj.swing.core.BasicRobot;
import org.assertj.swing.core.Robot;
import org.assertj.swing.edt.GuiActionRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Dimension;
import java.util.List;

import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.spy;


class RobotTest {

    private Robot robot;

    @BeforeEach
    void setUp() {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
    }

    @AfterEach
    void tearDown() {
        robot.cleanUp();
    }

    @Test
    void showWindow_ifPreferredWindowHeightExceedsTitleBarHeight_doesNotShrinkWindowToTitleBarHeight() {
        JTextField field = new JTextField();
        field.setColumns(10);
        JFrame frame = spy(createFrame(field));
        int titleBarInset = frame.getInsets().top;
        assumeThat(titleBarInset).isCloseTo(30, within(1));
        assumeThat(frame.getPreferredSize().height).isGreaterThan(titleBarInset);

        robot.showWindow(frame);

        ArgumentCaptor<Dimension> captor = ArgumentCaptor.forClass(Dimension.class);
        then(frame).should(atLeastOnce()).setSize(captor.capture());
        List<Dimension> setSizes = captor.getAllValues();
        Dimension lastSetDimension = setSizes.get(setSizes.size() - 1);
        assertThat(lastSetDimension.height).isGreaterThan(titleBarInset);
    }

    private JFrame createFrame(JComponent component) {
        return GuiActionRunner.execute(() -> {
            JFrame frame = new JFrame();
            frame.add(component);
            frame.pack(); // packed
            return frame;
        });
    }
}

It's all because of the shouldResize() method (see org.assertj.swing.monitor.WindowStatus#makeLargeEnoughToReceiveEvents). If the window's preferred size (which doesn't include insets) minus ≈30 pixels of the title bar top inset is lower than 30 pixels, the window is guaranteed to be shrunk to MINIMUM_WINDOW_SIZE (50,30). You also get ugly jittering of the pointer for several seconds.

// org.assertj.swing.monitor.WindowStatus#makeLargeEnoughToReceiveEvents
  @RunsInCurrentThread
  private void makeLargeEnoughToReceiveEvents(@Nonnull Window window) {
    if (!shouldResize(window)) {
      return;
    }
    window.setSize(MINIMUM_WINDOW_SIZE);
  }

Java 8.

Dominant language
Java
Stars
121
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-swing

All issues in assertj/assertj-swing

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.