Skip to content

Fix: Alignment issue for TwoLineListItem#6193

Open
KSSJW wants to merge 1 commit into
HMCL-dev:mainfrom
KSSJW-Contribution:twolinelistitem-fix
Open

Fix: Alignment issue for TwoLineListItem#6193
KSSJW wants to merge 1 commit into
HMCL-dev:mainfrom
KSSJW-Contribution:twolinelistitem-fix

Conversation

@KSSJW

@KSSJW KSSJW commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

修复 TwoLineListItem 对齐问题

缘由

合并 #6186 后,在不同字体下, TwoLineListItem 存在对齐问题。

涉及的 Issue

#6191

更改

  • 补充 TwoLineListItem 中的对齐。

实况

字体:Tahoma

修复前 修复后
Before1 After1
Before2 After2

@3gf8jv4dv 3gf8jv4dv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@KSSJW

KSSJW commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an alignment setting of 'Pos.CENTER' to the 'TwoLineListItem' constructor. The reviewer suggests using 'Pos.CENTER_LEFT' instead, to ensure that the list items are correctly aligned to the left horizontally while remaining vertically centered.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

getStyleClass().add(DEFAULT_STYLE_CLASS);
setMouseTransparent(true);

setAlignment(Pos.CENTER);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

对于列表项(List Item),通常需要保持水平方向左对齐,垂直方向居中对齐。如果使用 Pos.CENTER,在 VBox 的宽度大于子组件且 fillWidthfalse(或子组件限制了最大宽度)时,子组件会被水平居中,这通常不符合列表项的设计。建议使用 Pos.CENTER_LEFT,既能保证垂直居中,又能确保水平方向始终靠左对齐。

Suggested change
setAlignment(Pos.CENTER);
setAlignment(Pos.CENTER_LEFT);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/gemini Pos.CENTER_LEFT 是否会对其他情况产生影响?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用 Pos.CENTER_LEFT 是针对列表项(List Item)的通用最佳实践。在 JavaFX 中,setAlignment(Pos.CENTER_LEFT) 仅会影响容器内子组件的对齐方式,而不会改变容器本身的布局行为(如 VBox 的填充策略)。

只要 TwoLineListItem 的父容器没有强制其子组件进行拉伸(例如 VBoxfillWidth 属性为 true),使用 Pos.CENTER_LEFT 能够确保内容在垂直方向居中,同时在水平方向保持左对齐,这通常是列表项最符合直觉的视觉呈现方式。它不会对其他非列表场景产生负面影响,除非该组件被设计为在某些特定布局中需要强制水平居中,但在列表项的语境下,这通常不是预期的行为。

Suggested change
setAlignment(Pos.CENTER);
setAlignment(Pos.CENTER_LEFT);

@KSSJW

KSSJW commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

( •́ _ •̀)? 好像原来的左对齐没有问题(

字体:Tahoma

Pos.CENTER Pos.CENTER_LEFT
Center CenterLeft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants