Preface
I recently sorted out java's learning notes and found this long-standing swing shortcut (Black History) in an obscure corner.
When learning swing early, I didn't know there was a visual swing development tool yet, and I felt the development of GUI interface was cumbersome. I planned to develop a swing shortcut tool that provides fast layout, fast binding style, fast binding monitoring, and more powerful default components (text boxes with scrollbars, self-paging tables, etc.).
Because the learning cycle is too fast, almost no ideas are realized. While sorting out java learning notes, I found this gadget (call it a tool, if you like) 😂😂), Just thinking about sorting out a few interfaces was the initial idea of completing that time.
Source Link: GitHub - jiang-ruo/XLO-swing: Some handy swing gadgets to write while learning swing
What is Swing
Swing is a GUI toolkit designed for JAVA and is part of the basic class of JAVA. Swing is an AWT-based GUI tool, implemented with pure JAVA, independent of the graphical interface of each platform, and excellent cross-platform support.
Differences between Swing and AWT
-
AWT is a C/C++ program based on local methods, Swing is a Java program based on AWT.
-
Running speed: AWT > Swing
-
Swing's controls behave the same across platforms, and AWT's controls are based on each platform's own style.
Introduction to Toolkits
Easy to place components in batches;
Set the font and rounded corners of the component;
Table component: with paging and scrollbars;
Tools for batch binding buttons and events;
// This tool class is used to conveniently place components while setting their Layout to null class XLO.Swing.Util.LayoutNUllUtil { /** * @param panel Panel on which components will be bound * @param e Components that need to be placed * @param x Binding Location * @param y Binding Location * @param width Length of component * @param height Height of component */ public static void addElement(Container panel, Component e, int x, inty, int width, int height); /** * @param e Components that need to be placed * @param x Binding Location * @param y Binding Location * @param width Width of component * @param height Height of component */ public void addElement(Component e, int x, inty, int width, int height); /** * Add components in bulk, * @param x_offset Offset in X direction of control and previous control * @param y_offset Offset in Y direction of control and previous control * @param x Location of the first component * @param y Location of the first component * @param width Width of all components * @param height Height of all components * @param es Incoming Components */ public void addElement(int x_offset, int y_offset, int x, int y, int width, int height, Component... es); }
// Set component font size and rounded corners // TODO: Used to quickly set various properties of a component class XLO.Swing.Util.SetUIUtil { /** * Batch set component font size, default font is Font.PLAIN * @param size Typeface * @param assembly Components that require font settings */ public void setFontSize(int size, JComponent... assembly); /** * Set font properties of controls in batch * @param font * @param assembly */ public void setFontSize(Font font, JComponent... assembly); /** * Set the rounded corners of the component. Rounded radians default to the settings in XLO.Swing.Assembly.XLOBorder * @param assembly */ public void setRoundBorders(JComponent... assembly); /** * Set the border properties of the control in batches * @param border * @param assembly */ public void setRoundBorders(Border border, JComponent... assembly); /** * Set the border properties of the control in batches * @param arch angle * @param assembly */ public void setRoundBorders(int arch, JComponent... assembly); }
// Table Paging Component // Table base class with scrollbars class XLO.Swing.Assembly.XLOTableModel { /** * Set the header. * @param title */ public void setHeader(String... title); /** * Setting the display in a table * @param rows */ public void show(ArrayList<Object[]> rows); /** * Bind mouse click events */ public void addTableMouseListener(MouseListener listener); /** * * @return Returns the number of rows in the selected row */ public int getSelectedRow(); /** * Get the contents of the selected row * @return Returns an array of Object s. */ public Object[] getSelectRowInfo(); /** * Set the row height of the table. * @param height */ public void setRowHeight(int height); /** * Set the column width for each column * @param widths */ public void setColWidth(int... widths); } // Table Paging Component // PS: Now it seems that the function of this component is extremely inadequate, let's add the following to-do items( ε=ε=ε= (_)escape) // TODO: Add a table content buffer to record each addition to the buffer. // TODO: Save the total amount of data. // TODO: Recalculate the total number of pages after setting the page number information. class XLO.Swing.Assembly.XLOTableModel { /** * @param header Set Header */ public XLOPageTable(String[] header); /** * Used to display tabular information when determining the amount of data but no data * The number of tables per page needs to be set before calling this method, with a default of 5 data per page * @param total */ public void setPage(int total); /** * Information displayed on the current page of the table. * @param list */ public void setShowInfo(ArrayList<Object[]> list); /** * Previous page * @return */ public boolean previous(); /** * next page * @return */ public boolean next(); /** * @return Total number of pages */ public int getPage(); /** * @return Get the current page number */ public int getCurrentPage(); /** * @param currentPage Set Current Page Number */ public void setCurrentPage(int currentPage); /** * @return Number of displays per page */ public int getNum(); /** * Set the number of displays per page */ public void setNum(int num); }
// Tools for Bulk Boundary Binding Components class XLO.Control.ButtonClickAction{ /** * Bind monitoring to a button * @param btn Button * @param command Value of getActionCommand after clicking a button */ public void setCommand(AbstractButton btn, String command); /** * Multiple buttons bind to listen, incoming buttons and command s must correspond one to one * @param btns Button * @param commands Value of getActionCommand after clicking a button */ public void setCommand(AbstractButton[] btns, String[] commands) } // command Controller with Connection Protection class XLO.Control.ButtonAction;
Postnote
Although there are only a few tools in XLO-swing, there are many shortcomings in the view of these tools today. Publish and organize interface documents for your reference.
Source Link: GitHub - jiang-ruo/XLO-swing: Some handy swing gadgets to write while learning swing