In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the control location can be configured Swing desktop is how, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Friends who have used Wordpress or Joomla must be impressed by their flexible page layout. In Joomla, you can place a control anywhere on the page, such as left, right, menu, bottom, and so on.
So I also tried to implement a similar function on the Swing desktop, and after thinking about it, I found that it is actually easier for swing to achieve this function than to use html pages to achieve it.
First of all, we define a location interface, and the class that implements it indicates its location.
Public interface Arrange {public String getComponentName ();}
Second, inherit the Arrange interface and define the location interfaces that are not used, including
Public interface ArrangeBottom extends Arrange public interface ArrangeLeft extends Arrange public interface ArrangeLogo extends Arrange public interface ArrangeMainBottom extends Arrange public interface ArrangeMenuBar extends Arrange public interface ArrangeRight extends Arrange public interface ArrangeToolBar extends Arrange
The location of the above API is shown in the following figure:
Third: let's write a panel to implement the location interface.
For example: public class ZPanel extends JPanel implements ArrangeRight
Protected void paintComponent (Graphics g) {if (null! = wallpaper) {processBackground (g);} System.out.println ("f:paintComponent (Graphics g)");} public void setBackground () {wallpaper = new javax.swing.ImageIcon (getClass () .getResource ("/ com/peraglobal/workspace/initcompt/picpanel/kutoku.jpg") This.repaint ();}
Fourth: configure this class in the configuration file
Open the configuration file and press zlconfig.xml
Write
Fifth: load the configuration file
We use Spring to take out all the classes that implement a certain interface in the configuration file and load them to the specified location:
Map lefts = context.getBeansOfType (ArrangeLeft.class); ArrangeLeft agLeft; leftPanel.setLayout (new BorderLayout ()); JTabbedPane tabLeft = new JTabbedPane (); leftPanel.add (tabLeft); Iterator it = lefts.entrySet (). Iterator (); while (it.hasNext ()) {Map.Entry entry = (Map.Entry) it.next (); Object key = entry.getKey () Class newClass = Class.forName ((String) key); agLeft = (ArrangeLeft) newClass.newInstance (); tabLeft.add ((Component) agLeft, agLeft.getComponentName ());}
Sixth: we see that the Panel we just wrote has been loaded into the panel on the right
About the location of the controls can be configured on the Swing desktop is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.