2011-05-04 69 views
2

我一直试图改变UIManager使这些看起来很愚蠢的绿色正方形消失。我如何将这个外观和感觉改变为用户?它依赖于系统吗?编译我的代码的其他人有一个恒定的渐变。理想情况下,它只是一个坚实的广场,而不是较小的街区。改变摆动进度条的外观和感觉

感谢

enter image description here

+0

Netbeans?这只是一个IDE。你不是指Swing吗? – BalusC 2011-05-04 19:37:32

+0

是的。我使用NetBeans作为编辑器,并提到它以防在其中设置简单的方法。但是,能够更改/定制进度条(而不是整个应用程序)的外观会很好。 – NickG 2011-05-06 17:07:32

+0

听起来好像你在问如何改变Netbeans的look'n'feel。这没有意义。这与问如何改变记事本的look'n'feel是一样的。我编辑了标题+标签。 – BalusC 2011-05-06 17:09:18

回答

4

您是否尝试过将其设置为系统的(用户)的外观和感觉?

设置的外观和感觉,最简单的方法是通过启动GUI调用后:

try 
{ 
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
} 
catch (Exception e) 
{ 
    // ... 
} 

随着中说,上面似乎是Windows XP的主题,可能确实是系统(用户)主题。除非有很好的理由(例如客户/用户需求),否则我通常远离GUI中的自定义主题。

也就是说,上面的代码使得它与系统相关,这是,因为它符合用户的预期。

+0

我已经尝试过它并且可以工作(这是默认设置)。旧的学生java看起来过时了,但确实改变了进度条。谢谢(你的)信息。 – NickG 2011-05-06 17:01:48

+0

想补充一点,pickypg入门的重要注意事项是在应用程序加载之前编写命令。我尝试了应用程序加载后但显示之前,它不工作。对于额外的定制,下面的piesnikowski的答案是一个例子。 – NickG 2011-05-09 18:26:18

0

编辑 下面的代码更改整个JFrame的L & F。

static Main m;//Reference to JFrame to be updated 
static String maxOSLookAndFeel = "ch.randelshofer.quaqua.QuaquaLookAndFeel";//Package of particular L&F  
private void MacOSLFjMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MacOSLFjMenuItemActionPerformed 
        // TODO add your handling code here: 
        SwingUtilities.invokeLater(new Runnable() { 

         public void run() { 
          try { 
           UIManager.setLookAndFeel(maxOSLookAndFeel); 
           SwingUtilities.updateComponentTreeUI(m); 
           m.validate(); 
          } catch (ClassNotFoundException ex) { 
           Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
          } catch (InstantiationException ex) { 
           Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
          } catch (IllegalAccessException ex) { 
           Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
          } catch (UnsupportedLookAndFeelException ex) { 
           Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
          } 
         } 
        }); 

       }//GEN-LAST:event_MacOSLFjMenuItemActionPerformed 

Secundo: 在我看来(GOOGLE了很多,用的expirience)这是不可能只影响一个JComponent的同时,您可以将新的大号& F.您更改信用证&的F整个JFrame中或你可以Write your own Swing Component.

实现目标的另一种方法是研究java source code并找到JProgressBar图像正在添加到组件的位置,并通过扩展JProgressBar覆盖此方法。

+0

c&p生成的代码来解释究竟是什么..? – kleopatra 2011-05-05 12:56:13

+0

好的。我假设我将不得不下载这个外观和感觉,并设置所有设置,使其看起来像一个mac,我想会改变我整个应用程序的外观,但真的只是看着可能只改变我的进度条。 – NickG 2011-05-06 17:05:47

+0

Klepoatra你说得对。这是来自我的项目的C&P,但现在我尽我所能编辑了我的帖子。干杯!:) – 2011-05-08 08:35:47

2

“这些看起来很蠢的绿色正方形”是Windows XP的Look Nad Feel元素。如果你希望它们看起来不同,你可以改变这个特定组件的外观和感觉。

只要使用以下解决方法:

try { 
    javax.swing.UIManager.setLookAndFeel(/* Look and Feel for your JProgressBar*/); 
} 
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 
    Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 
} 

MyProgressBar = new javax.swing.JProgressBar(); 

try { 
    javax.swing.UIManager.setLookAndFeel(/* Previous, main Look and Feel */); 
} 
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 
    Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); 
} 

我使用这个代码给了JFileChooser的另一外观和它完美的作品。

您只需在创建组件之前更改外观,然后在创建之后恢复上一个。

+1

作品非常感谢!我不会想到这样的事情是可能的。 – Teddy 2017-02-17 07:17:24