https://github.com/HTTP-RPC/Sierra Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} HTTP-RPC / Sierra Public * Notifications * Fork 0 * Star 47 Declarative UI for Java License Apache-2.0 license 47 stars 0 forks Star Notifications * Code * Issues 2 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights HTTP-RPC/Sierra This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 12 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/H] Use Git or checkout with SVN using the web URL. [gh repo clone HTTP-R] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @gk-brown gk-brown Add action handler example. ... ec7e5dc Jan 3, 2023 Add action handler example. ec7e5dc Git stats * 140 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .idea Stub out support for alignment values. Dec 28, 2022 README Add action handler example. Jan 3, 2023 gradle/wrapper Stub out project structure. Jul 18, 2022 sierra-test Add action handler example. Jan 3, 2023 sierra/src/main/java/org/httprpc/sierra Drop SwingUIBuilder. Jan 1, 2023 .gitignore Stub out project structure. Jul 18, 2022 LICENSE Initial commit Jul 18, 2022 README.md Add action handler example. Jan 3, 2023 build.gradle Drop SwingUIBuilder. Jan 1, 2023 gradlew Stub out project structure. Jul 18, 2022 gradlew.bat Stub out project structure. Jul 18, 2022 settings.gradle Remove extra whitespace. Dec 13, 2022 sierra.png Update README.md. Jul 18, 2022 View code [ ] Introduction Contents Getting Sierra Sierra Classes Focus Management Examples Border Layout Component Orientation Baseline Alignment Box Alignment Grid Alignment Action Handling Periodic Table Additional Information README.md Releases Maven Central javadoc Introduction Sierra is an open-source framework for simplifying development of Java Swing applications. It provides a convenient DSL for declaratively constructing Swing component hierarchies. The framework is extremely lightweight (less than 32KB) and has no external dependencies. The project's name comes from the nautical S or Sierra flag, representing the first letter in "Swing": [sierra] This guide introduces the Sierra framework and provides an overview of its key features. Contents * Getting Sierra * Sierra Classes * Examples * Additional Information Getting Sierra Sierra is distributed via Maven Central at org.httprpc:sierra. Java 11 or later is required. Sierra Classes Sierra provides the UIBuilder class, whose methods can be used to declaratively establish a hierarchy of user interface elements. The methods defined by this class form a DSL, or "domain-specific language", that makes it easy to visualize the resulting output: * column() - produces an instance of ColumnPanel, a container that automatically arranges sub-components along the y-axis * row() - produces an instance of RowPanel, a container that automatically arranges sub-components along the x-axis * stack() - produces an instance of StackPanel, a container that automatically arranges sub-components by z-order These components offer an alternative to the standard Java layout managers, which can often be limiting or difficult to use in practice. ColumnPanel optionally aligns sub-components to a grid, similar to an HTML table or GridBagLayout. RowPanel optionally aligns sub-components to baseline, similar to FlowLayout. Additionally, UIBuilder provides this method for declaring a panel's contents: public static Cell cell(C component) { ... } The returned Cell instance can be used to further customize the layout or configuration of the provided component: * weightBy() - specifies the amount of excess space in a container that should be allocated to the component, relative to other weighted components * with() - accepts a callback that can be used to set properties or invoke methods on the component Finally, these UIBuilder methods can be used to declare spacer cells in column and row panels, similar to BoxLayout: * strut() - declares a fixed-size spacer cell * glue() - declares a flexible spacer cell Sierra also includes the TextPane and ImagePane components, which provide an alternative to JLabel for displaying basic text or image content, respectively. TextPane supports wrapping text without requiring HTML, and ImagePane supports scaling without requiring an intermediate BufferedImage. For example, the following code declares a column panel containing a graphic and a simple greeting: setContentPane(column(4, false, cell(new ImagePane(image, true)), cell(new TextPane("Hello, World!", false)).with(textPane -> textPane.setHorizontalAlignment(HorizontalAlignment.CENTER)) ).with(contentPane -> { contentPane.setBackground(Color.WHITE); contentPane.setOpaque(true); contentPane.setBorder(new EmptyBorder(8, 8, 8, 8)); }).getComponent()); The resulting output is shown below: [greeting] The complete source code can be found here. Focus Management Sierra additionally provides the ScrollingKeyboardFocusManager class, which can be used to ensure that components are automatically scrolled into view when focused. It can be installed at application startup as follows: KeyboardFocusManager.setCurrentKeyboardFocusManager(new ScrollingKeyboardFocusManager()); Examples This section includes examples demonstrating usage of UIBuilder with the Flat look-and-feel. Border Layout Inspired by the border layout tutorial example. BorderTest.java [border] Component Orientation Inspired by the flow layout tutorial example. OrientationTest.java [orientation] Baseline Alignment Demonstrates baseline alignment. BaselineTest.java [baseline] Box Alignment Demonstrates box alignment. BoxTest.java [box] Grid Alignment Demonstrates grid alignment. FormTest.java [form] GridTest.java [grid] AlignmentTest.java [alignment] Action Handling Demonstrates associating an action handler with a button. ActionTest.java [action] Periodic Table Inspired by Wikipedia's classification of the elements. PeriodicTableTest.java [periodic-table] Additional Information This guide introduced the Sierra framework and provided an overview of its key features. For additional information, see the source code. About Declarative UI for Java Topics java swing dsl declarative-ui Resources Readme License Apache-2.0 license Stars 47 stars Watchers 0 watching Forks 0 forks Releases 1 Sierra 1.2.2 Latest Jan 1, 2023 Packages 0 No packages published Languages * Java 100.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.