解决java菜单界面 中文 乱码问题

解决java菜单界面 中文 乱码问题,第1张

解决java菜单界面 中文 乱码问题

在用Java做数据库实验时遇到了这个问题,查找csdn后获得了这类解答:https://blog.csdn.net/SICAUliuy/article/details/82559459?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164130440216780269866045%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164130440216780269866045&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-82559459.pc_search_result_cache&utm_term=Java+%E8%8F%9C%E5%8D%95%E4%B9%B1%E7%A0%81&spm=1018.2226.3001.4187https://blog.csdn.net/SICAUliuy/article/details/82559459?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164130440216780269866045%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164130440216780269866045&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-82559459.pc_search_result_cache&utm_term=Java+%E8%8F%9C%E5%8D%95%E4%B9%B1%E7%A0%81&spm=1018.2226.3001.4187

不知道大家好不好用,但是对我来说不太好用,因为这是java.awt.frame自身的问题,修改编译器的话反而会让其他的没有问题的类出现问题。

最终查找源码可以发现,现在,awt下面有了一个扩展版本java.awt.Jframel,他已经解决了中文乱码问题。只要将原来frame里所有的变量名(如Panel,MenuBar,Menu等)前面加 ‘J’ 就能在大部分情况下完美适配。注意:相关函数中间若含变量名也同理(如setMenuBar 应该改为 setJMenuBar)。

以下是Jframe 源码前的解释:

 An extended version of java.awt.frame that adds support for the JFC/Swing component architecture. You can find task-oriented documentation about using Jframe in The Java Tutorial, in the section How to Make frames .
The Jframe class is slightly incompatible with frame. Like all other JFC/Swing top-level containers, a Jframe contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the Jframe. This is different from the AWT frame case. As a convenience, the add, remove, and setLayout methods of this class are overridden, so that they delegate calls to the corresponding methods of the ContentPane. For example, you can add a child component to a frame as follows:
         frame.add(child);
   
And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the Jframe to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a Jframe.
Unlike a frame, a Jframe has some notion of how to respond when the user attempts to close the window. The default behavior is to simply hide the Jframe when the user closes the window. To change the default behavior, you invoke the method setDefaultCloseOperation. To make the Jframe behave the same as a frame instance, use setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE).
For more information on content panes and other features that root panes provide, see Using Top-Level Containers  in The Java Tutorial.
In a multi-screen environment, you can create a Jframe on a different screen device. See frame for more information.

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5697316.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存