- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我有一个用户可以更改外观的界面。这是界面:
http://www.hostingpics.net/viewer.php?id=579250themesApp.jpg
以及每个按钮的代码:
//The JDesktop Frame contains all the Internal Frames
JDesktop p = new JDesktop();
try {
UIManager.setLookAndFeel( new javax.swing.plaf.metal.MetalLookAndFeel());
SwingUtilities.updateComponentTreeUI(p);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(paramApparence.class.getName()).log(Level.SEVERE, null, ex);
}
对于每个按钮,我仅更改外观和感觉(金属/Nimbus 等)
当我单击按钮来更改外观和感觉时,它给了我:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
这是完整的堆栈跟踪:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:217)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:286)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1012)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1624)
at sun.swing.MenuItemLayoutHelper.reset(MenuItemLayoutHelper.java:125)
at javax.swing.plaf.synth.SynthMenuItemLayoutHelper.<init>(SynthMenuItemLayoutHelper.java:119)
at javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:498)
at javax.swing.plaf.synth.SynthMenuUI.paint(SynthMenuUI.java:283)
at javax.swing.plaf.synth.SynthMenuUI.update(SynthMenuUI.java:248)
at javax.swing.JComponent.paintComponent(JComponent.java:778)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:887)
at javax.swing.JComponent.paint(JComponent.java:1063)
at javax.swing.JComponent.paintChildren(JComponent.java:887)
at javax.swing.JComponent.paint(JComponent.java:1063)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:585)
at javax.swing.JComponent.paintChildren(JComponent.java:887)
at javax.swing.JComponent.paint(JComponent.java:1063)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:295)
at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:217)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:286)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1012)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1624)
at sun.swing.MenuItemLayoutHelper.reset(MenuItemLayoutHelper.java:126)
at javax.swing.plaf.synth.SynthMenuItemLayoutHelper.<init>(SynthMenuItemLayoutHelper.java:119)
at javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:498)
at javax.swing.plaf.synth.SynthMenuItemUI.paint(SynthMenuItemUI.java:283)
at javax.swing.plaf.synth.SynthMenuItemUI.update(SynthMenuItemUI.java:247)
at javax.swing.JComponent.paintComponent(JComponent.java:778)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:887)
at javax.swing.JComponent.paint(JComponent.java:1063)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:295)
at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:217)
at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:286)
at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1012)
at javax.swing.JComponent.getFontMetrics(JComponent.java:1624)
at sun.swing.MenuItemLayoutHelper.reset(MenuItemLayoutHelper.java:126)
at javax.swing.plaf.synth.SynthMenuItemLayoutHelper.<init>(SynthMenuItemLayoutHelper.java:119)
at javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:498)
at javax.swing.plaf.synth.SynthMenuItemUI.paint(SynthMenuItemUI.java:283)
at javax.swing.plaf.synth.SynthMenuItemUI.update(SynthMenuItemUI.java:247)
at javax.swing.JComponent.paintComponent(JComponent.java:778)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintChildren(JComponent.java:887)
at javax.swing.JComponent.paint(JComponent.java:1063)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:295)
at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
最佳答案
例如(正确的方法之一)
默认情况下需要JFrame.pack()
,而不是像setVisible(false)然后true
那样的另一个woodoos,或者将DecorationsType
更改为JFrame
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
public class TestInternalFrame {
private JFrame frame = new JFrame("Test");
public TestInternalFrame() {
final JInternalFrame internal = new JInternalFrame("test");
final JInternalFrame hidden = new JInternalFrame("test");
hidden.setBounds(1000, 1000, 1, 1);
hidden.setVisible(true);
internal.setVisible(true);
internal.setBounds(0, 0, 100, 100);
JDesktopPane pane = new JDesktopPane();
pane.add(internal);
pane.add(hidden);
pane.setPreferredSize(new Dimension(10000, 10000));
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(new JScrollPane(pane,
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
DefaultComboBoxModel model = new DefaultComboBoxModel();
UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
for (int i = 0; i < info.length; i++) {
model.addElement(info[i].getName());
}
final JComboBox box = new JComboBox(model);
box.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if (box.getSelectedItem().equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
UIManager.getLookAndFeel().uninitialize();
UIManager.setLookAndFeel(info.getClassName());
SwingUtilities.updateComponentTreeUI(frame);
break;
}
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(TestInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(TestInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(TestInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(TestInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
frame.add(box, BorderLayout.NORTH);
frame.setPreferredSize(new Dimension(400, 300));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
TestInternalFrame tif = new TestInternalFrame();
}
});
}
}
关于java - 更改 swing 应用程序的外观和感觉 (UIManager) 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15657934/
您可以将自定义皮肤/外观应用于 SSMS 吗?我正在考虑类似于大多数 IDE 中的深色主题(黑色背景、黄色字体)的做法 最佳答案 我决定在 SSMS 2012 上尝试一些简单的操作: 转到http:/
WordPress主题开发中如何在外观部分显示菜单选项?我可以看到主题、自定义和编辑器选项。这段代码有什么问题- function pietergoosen_theme_setup() { reg
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我正在我的一个项目中使用 JTabbedPane,并且我正在尝试更改应用程序的外观和感觉。当我设置窗口的外观和感觉(以及与此相关的任何其他外观和感觉)时,所有按钮、检查按钮等都会更改为它们应该的外观,
如何更改使用 SFAuthenticationSession 时显示的 SafariVC 上的tintColor 和 barTintColor? 我尝试更改 UINavigationBar 、 UIT
我想让 editText 看起来像这样: 设置editText的背景后我还应该做什么如何通过代码让文本在edittext中开始。 最佳答案 您是否想让 EditText 默认说“用户名”,但不是实际的
我在 didFinishLaunchingWithOptions 末尾使用以下代码 [[UITableViewHeaderFooterView Appearance] setTintColor:[UI
我的 ActionBar 中有 android.support.v7.widget.ShareActionProvider 菜单。 当我点击“分享”时,应用列表显示为弹出菜单。 当我在 Google
在使用 shiny 作为调查工具时,我想将 slider 用作“李克特式问题”。 因此,我想自定义 slider 末端的标题,使其有点像“我完全同意”和“我完全不同意”。有没有一种流畅的方法可以做到这
我正在阅读 Laravel 文档,试图更深入地了解该框架,但我在外观方面遇到了一些麻烦。我想我明白它们是什么,它们主要是为了方便访问 Laravel 核心而使用。 我对这个主题感到困惑: How do
我正在制作一款游戏,我想要一个用户可以填写表格提出想法或错误的地方,但希望它看起来与游戏图形/按钮等的其余部分相似。我不知道如何制作带图片的自定义文本字段。我希望最终结果如下所示: 我知道如何设置自定
我的 Storyboard中有多个 UINavigationController。由于我使用的是 tabbarcontroller,因此每个选项卡项都在其 ViewController 之前嵌入了自己
我需要创建一个外观,将请求转发到其他 Web 服务。 除了转发之外,外观只会对用户进行身份验证/授权。 实现这个的好方法是什么? 我曾经使用 Jersey,也许有比手动创建 WebTarget 更好的
我使用了 windows 安装程序(msi 项目),实际上我在安装后得到了 msi 文件,它会在桌面上显示一个快捷方式。 我的问题是,当我双击我的应用程序的快捷方式时,它会显示类似安装的内容,然后它会
我通过 trayIcon.displayMessage(...) 在系统托盘上显示消息,但它们看起来不太好。我试图将它们的外观更改为系统标准,但在创建图标之前调用 UIManager.setLookA
我正在尝试为我的应用程序应用深色主题,当我调用深色主题时遇到问题,代码在重新启动应用程序之前不起作用。我在设置 View Controller 中使用 UISwtich 调用黑暗模式。当我打开深色模式
我正在为我不拥有或无法访问其源代码的 Swing 应用程序编写插件。在我的部分 UI 中,我想使用特定的颜色来匹配我的图标。 在这种情况下,我想创建一个具有特定背景颜色的 JPanel。 final
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: Look and feel in java 是否有第三方漂亮的 L&F for Java swing 应用程序?默认
我想要 JButton 的外观: 我尝试通过这种方式更改 Windows 的外观: UIManager.setLookAndFeel("com.sun.java.swing.plaf.window
是否可以更改 UITabBarController 的外观? 例如,将 tabBarItems 垂直(而不是水平)排列在 View 的中心(而不是锁定在底部) 最佳答案 对于你想要的改变,没有。 您所
我是一名优秀的程序员,十分优秀!