Replace inline styles with CSS classes#15694
Conversation
Review Summary by QodoReplace inline styles with CSS classes for better maintainability
WalkthroughsDescription• Replace inline setStyle() calls with CSS classes across multiple UI components • Move styling logic from Java code into centralized theme CSS file • Add new CSS classes for common styling patterns (bold, padding, alignment) • Improve maintainability by consolidating style definitions in one location Diagramflowchart LR
A["Java Components<br/>setStyle calls"] -- "Replace with<br/>getStyleClass.add" --> B["CSS Classes"]
B -- "Define in" --> C["jabref-theme.css"]
C -- "Applied to" --> D["UI Components<br/>CitationKeyPatternsPanel<br/>LatexCitationsTab<br/>CitationRelationsTab<br/>MainTable<br/>FileSelectionPage"]
File Changes1. jabgui/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java
|
Code Review by Qodo
Context used 1. Trivial comments in updateItem
|
Maran23
left a comment
There was a problem hiding this comment.
Overall looks good, some comments and suggestions.
After running a grep search for color-related setStyle(...) calls, only two files remained:
--> WelcomeTab.java
--> ChatMessageComponent.java
This is fine. ChatMessageComponent is reworked anyway currently. And WelcomeTab might be a good follow up. Because I think this can be solved with a styleClass, but need to be investigated.
| if (item == null || item.getEntryType() == null) { | ||
| setStyle(""); | ||
| } else if (isSelected()) { | ||
| setStyle("-fx-background-color: -fx-selection-bar"); |
There was a problem hiding this comment.
This style is not set anymore, isn't it? Is there a reason for it?
There was a problem hiding this comment.
I checked it again and from what I understood, JavaFX already applies the selected row styling automatically for table rows through the existing selection CSS.
When I tested it locally, the selected row was still highlighted correctly even after removing the inline setStyle(...), so it seemed safe to remove this one as well.
| /// @param tooltipText tooltip text | ||
| private void styleLabel(Label label, String tooltipText) { | ||
| label.setStyle("-fx-padding: 5px"); | ||
| label.getStyleClass().add("padded-label"); |
There was a problem hiding this comment.
I would recommend to name this to padding-5px, so that it is clear this sets a 5px padding. Since we might have more variants at one point.
| hBox.getChildren().add(link); | ||
| hBox.setSpacing(2d); | ||
| hBox.setStyle("-fx-alignment: center;"); | ||
| hBox.getStyleClass().add("centered-container"); |
There was a problem hiding this comment.
I would recommend something like alignment-center, which also follows frameworks like tailwind, so developers will understand it much better
There was a problem hiding this comment.
or even shorter, we could do align-center
| Tooltip.install(header, new Tooltip(MainTableColumnModel.Type.INDEX.getDisplayName())); | ||
| column.setGraphic(header); | ||
| column.setStyle("-fx-alignment: CENTER-RIGHT;"); | ||
| column.getStyleClass().add("right-aligned-column"); |
There was a problem hiding this comment.
or even shorter, we could do align-center-right
| .withGraphic(this::createGroupColorRegion) | ||
| .install(column); | ||
| column.setStyle("-fx-padding: 0 0 0 0;"); | ||
| column.getStyleClass().add("main-table-column-no-padding"); |
|
Also found 3 locations where |
|
I took a look at the remaining I read a bit about possible alternatives like pseudo-classes, but since I’m still learning the codebase and getting familiar with contributing to JabRef, I preferred to keep this PR focused and avoid introducing regressions in more dynamic UI behavior. I’d definitely be interested in revisiting those later once I better understand the JavaFX styling patterns used in the project. |
Fine for me! |
Maran23
left a comment
There was a problem hiding this comment.
Some changes are still pending.
Note: My rationale by reusing the same styleClass like padding-0 is so that our CSS file is smaller and we have less clutter and more generic styleClassess, which makes it much more maintainable.
| -fx-padding: 5px; | ||
| } | ||
|
|
||
| #citationRelationsTab .align-center { |
There was a problem hiding this comment.
just .align-center without the #citationRelationsTab
|
|
||
| /* CitationRelationsTab */ | ||
|
|
||
| #citationRelationsTab .padding-5px { |
There was a problem hiding this comment.
just .padding-5px without the #citationRelationsTab (so it is standalone and reusable)
| -fx-font-weight: bold; | ||
| } | ||
|
|
||
| #entryEditor .latex-citations-box { |
There was a problem hiding this comment.
Remove and use padding-0 instead in code
| VBox vBox = new VBox(); | ||
| vBox.getChildren().add(progressIndicator); | ||
| vBox.setStyle("-fx-alignment: center;"); | ||
| vBox.getStyleClass().add("centered-container"); |
| vBox.getChildren().add(label); | ||
| vBox.setSpacing(2d); | ||
| vBox.setStyle("-fx-alignment: center;"); | ||
| vBox.getStyleClass().add("centered-container"); |
| hBox.getChildren().add(link); | ||
| hBox.setSpacing(2d); | ||
| hBox.setStyle("-fx-alignment: center;"); | ||
| hBox.getStyleClass().add("centered-container"); |
Maran23
left a comment
There was a problem hiding this comment.
Looks good, thanks! Will create a follow up soon for styleProperty and Welcome section.
|
Congratulations on your first accepted pull request at JabRef! |
* upstream/main: (21 commits) chore(deps): update dependency com.konghq:unirest-modules-gson to v4.10.0 (JabRef#15715) Add manual tests (JabRef#15351) Refactored the comments for UnlinkedFilesCrawler (JabRef#15709) Replace inline styles with CSS classes (JabRef#15694) add test case for multiple authors in csl citaiton (JabRef#15707) fix invalid desktop file for linux (JabRef#15702) Change FileKeystore and Folder fields to disable/enable (JabRef#15685) Chore(deps): Bump org.openrewrite.recipe:rewrite-recipe-bom from 3.30.0 to 3.30.1 (JabRef#15696) New Crowdin updates (JabRef#15693) Chore(deps): Bump dev.langchain4j:langchain4j-bom in /versions (JabRef#15698) Chore(deps): Bump org.apache.logging.log4j:log4j-to-slf4j in /versions (JabRef#15700) chore(deps): update dependency org.apache.logging.log4j:log4j-to-slf4j to v2.26.0 (JabRef#15699) Chore(deps): Bump org.openrewrite.rewrite from 7.32.1 to 7.32.2 (JabRef#15697) Chore(deps): Bump jablib/src/main/resources/csl-locales (JabRef#15689) Fix month checker regex (JabRef#15678) Chore(deps): Bump com.dlsc.gemsfx:gemsfx in /versions (JabRef#15692) Chore(deps): Bump org.hisp.dhis:json-tree in /versions (JabRef#15691) Chore(deps): Bump jablib/src/main/resources/csl-styles (JabRef#15690) New Crowdin updates (JabRef#15687) Chore(deps): Bump com.konghq:unirest-java-core in /versions (JabRef#15683) ...
Related issues and pull requests
Closes #15686
Closes #15686
PR Description
This PR replaces several inline setStyle(...) calls with CSS style classes in order to move styling logic from Java code into the theme files.
After running a grep search for color-related setStyle(...) calls, only two files remained:
--> WelcomeTab.java
--> ChatMessageComponent.java
I intentionally did not modify them because WelcomeTab.java already contains a comment explaining that a CSS class was insufficient in that specific case, and ChatMessageComponent.java uses dynamically generated colors. Since I am still relatively new to JavaFX and the project's styling system, I preferred not to touch the more complex cases to avoid accidentally breaking existing behavior.
Apart from these two files, I made sure that all remaining color-related inline styles were replaced with CSS classes. I also replaced most of the simpler setStyle(...) calls related to padding, alignment, font weight, and similar properties.
Steps to test
1- Run JabRef locally.
2 - Switch between light and dark themes.
3 - Open the affected UI areas and verify that the styling and layout still behave correctly.
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)