Skip to content

Replace inline styles with CSS classes#15694

Merged
Maran23 merged 3 commits into
JabRef:mainfrom
AnasKh21:fix-issue-15686-setstyle
May 10, 2026
Merged

Replace inline styles with CSS classes#15694
Maran23 merged 3 commits into
JabRef:mainfrom
AnasKh21:fix-issue-15686-setstyle

Conversation

@AnasKh21

@AnasKh21 AnasKh21 commented May 7, 2026

Copy link
Copy Markdown
Contributor

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

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • [/] I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I added a screenshot in the PR description showing a library with a single entry with me as author and as title the issue number
  • [/] I described the change in CHANGELOG.md in a way that can be understood by the average user (if change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Replace inline styles with CSS classes for better maintainability

✨ Enhancement

Grey Divider

Walkthroughs

Description
• 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
Diagram
flowchart 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"]
Loading

Grey Divider

File Changes

1. jabgui/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java ✨ Enhancement +10/-8

Replace inline row styling with CSS class

jabgui/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java


2. jabgui/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTab.java ✨ Enhancement +5/-5

Replace multiple inline styles with CSS classes

jabgui/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTab.java


3. jabgui/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java ✨ Enhancement +5/-5

Replace alignment and padding styles with CSS classes

jabgui/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java


View more (6)
4. jabgui/src/main/java/org/jabref/gui/externalfiles/FileSelectionPage.java ✨ Enhancement +2/-2

Replace progress pane and label styles with CSS

jabgui/src/main/java/org/jabref/gui/externalfiles/FileSelectionPage.java


5. jabgui/src/main/java/org/jabref/gui/externalfiles/ImportResultsPage.java ✨ Enhancement +2/-2

Replace progress pane and summary label styles

jabgui/src/main/java/org/jabref/gui/externalfiles/ImportResultsPage.java


6. jabgui/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java ✨ Enhancement +3/-3

Replace column alignment and padding inline styles

jabgui/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java


7. jabgui/src/main/java/org/jabref/gui/texparser/ParseLatexResultView.java ✨ Enhancement +1/-1

Replace reference text fill style with CSS class

jabgui/src/main/java/org/jabref/gui/texparser/ParseLatexResultView.java


8. jabgui/src/main/java/org/jabref/gui/util/TextFlowLimited.java ✨ Enhancement +1/-1

Replace more link background color with CSS class

jabgui/src/main/java/org/jabref/gui/util/TextFlowLimited.java


9. jabgui/src/main/resources/org/jabref/gui/jabref-theme.css ✨ Enhancement +62/-0

Add new CSS classes for styling patterns

jabgui/src/main/resources/org/jabref/gui/jabref-theme.css


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Context used

Grey Divider


Remediation recommended

1. Trivial comments in updateItem 📘 Rule violation ⚙ Maintainability
Description
New comments in HighlightTableRow.updateItem restate what the code already makes obvious
(removing/adding a style class). This reduces signal-to-noise and violates the guideline that
comments should explain rationale (“why”), not narrate behavior.
Code

jabgui/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java[R128-136]

+            // Style used to highlight the default entry type row
            super.updateItem(item, empty);
-            if (item == null || item.getEntryType() == null) {
-                setStyle("");
-            } else if (isSelected()) {
-                setStyle("-fx-background-color: -fx-selection-bar");
-            } else if (CitationKeyPatternsPanelViewModel.ENTRY_TYPE_DEFAULT_NAME.equals(item.getEntryType().getName())) {
-                setStyle("-fx-background-color: -fx-default-button");
-            } else {
-                setStyle("");
+
+            getStyleClass().remove(DEFAULT_ROW_STYLE_CLASS);
+            // Reapply the style only for the default entry type row
+            if (item != null
+                    && item.getEntryType() != null
+                    && CitationKeyPatternsPanelViewModel.ENTRY_TYPE_DEFAULT_NAME.equals(item.getEntryType().getName())) {
+                getStyleClass().add(DEFAULT_ROW_STYLE_CLASS);
Evidence
PR Compliance ID 7 requires that added comments explain intent/rationale rather than trivially
restating code. The added comments (Style used to highlight..., Reapply the style...) directly
narrate the subsequent style-class operations without adding additional rationale.

AGENTS.md
jabgui/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java[128-136]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`HighlightTableRow.updateItem` adds comments that restate obvious behavior (adding/removing a CSS class) rather than explaining rationale.

## Issue Context
Per codebase conventions, comments should focus on the “why” (constraints, non-obvious reasons) and avoid narrating self-explanatory code.

## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java[128-136]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@github-actions github-actions Bot added good first issue An issue intended for project-newcomers. Varies in difficulty. component: ui component: css status: no-bot-comments labels May 7, 2026
@Maran23 Maran23 self-requested a review May 7, 2026 13:00

@Maran23 Maran23 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This style is not set anymore, isn't it? Is there a reason for it?

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.

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would recommend something like alignment-center, which also follows frameworks like tailwind, so developers will understand it much better

@Maran23 Maran23 May 7, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

alignment-center-right

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe just padding-0 ?

Comment thread jabgui/src/main/resources/org/jabref/gui/jabref-theme.css Outdated
@Maran23

Maran23 commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Also found 3 locations where styleProperty() is used. Could you use take a look at them?

@AnasKh21

AnasKh21 commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

I took a look at the remaining styleProperty() usages. From what I understood, they are a bit different from the fixed inline setStyle(...) calls because they are tied to dynamic bindings and animations.

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.

@Maran23

Maran23 commented May 9, 2026

Copy link
Copy Markdown
Collaborator

I took a look at the remaining styleProperty() usages. From what I understood, they are a bit different from the fixed inline setStyle(...) calls because they are tied to dynamic bindings and animations.

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 Maran23 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 {

@Maran23 Maran23 May 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just .align-center without the #citationRelationsTab


/* CitationRelationsTab */

#citationRelationsTab .padding-5px {

@Maran23 Maran23 May 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just .padding-5px without the #citationRelationsTab (so it is standalone and reusable)

-fx-font-weight: bold;
}

#entryEditor .latex-citations-box {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

align-center

vBox.getChildren().add(label);
vBox.setSpacing(2d);
vBox.setStyle("-fx-alignment: center;");
vBox.getStyleClass().add("centered-container");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

align-center

hBox.getChildren().add(link);
hBox.setSpacing(2d);
hBox.setStyle("-fx-alignment: center;");
hBox.getStyleClass().add("centered-container");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

align-center

@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels May 9, 2026
@github-actions github-actions Bot added status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels May 9, 2026

@Maran23 Maran23 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, thanks! Will create a follow up soon for styleProperty and Welcome section.

@Maran23 Maran23 added this pull request to the merge queue May 10, 2026
@github-actions github-actions Bot added the status: to-be-merged PRs which are accepted and should go into the merge-queue. label May 10, 2026
Merged via the queue into JabRef:main with commit fc14b60 May 10, 2026
53 checks passed
@Maran23

Maran23 commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Congratulations on your first accepted pull request at JabRef!

Siedlerchr added a commit to pluto-han/jabref that referenced this pull request May 11, 2026
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: css component: ui good first issue An issue intended for project-newcomers. Varies in difficulty. status: no-bot-comments status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace all setStyle(..) calls with proper styleClasses

2 participants