我一直致力于将 Java 应用程序从 WindowsLookAndFeel 转换到 Nimbus,尽管 Nimbus 存在缺陷,但在很大程度上取得了成功。我的用户总体上喜欢 Nimbus LaF,但不喜欢某些细节,其中一些细节我通过查阅本网站上的先前问题进行了更改。示例:我从 Windows LaF(他们喜欢)复制了 LeafIcon、ClosedIcon 和 OpenIcon,并在 Nimbus 版本中使用它们,以获得 LaF 的完美组合。
卡在最后一个(?)问题上。
我有一个带有子类 DefaultCellRenderer 的 JTree 来创建适当的节点显示。这在 WindowsLookAndFeel 下工作正常。
问题: 在 WindowsLaF 下,当一个节点被选中时,该节点的文本会被高亮显示,其效果在视觉上很容易理解。在 Nimbus 下,当一个节点被选中时,突出显示是用一个(相当暗的)颜色条完成的,该颜色条运行树窗口的宽度(而不仅仅是文本的宽度),效果令人不安。
所以:我只是希望 WindowsLaF 处理 Nimbus LaF 中突出显示的 JTree 节点(即彩色背景只有文本的宽度,最好是我可以选择的更好的颜色)。我怀疑这意味着我需要将正确的 Painter 分配给 “Tree:TreeCell[Focused+Selected].backgroundPainter”,但是我不知道怎么写。
欢迎提出建议。
编辑
使用 Java 7 查看奇怪的选定节点突出显示!
public class TreeBorder {
public static void main( String[] args ) {
try{
for( UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() ) {
if( "Nimbus".equals( info.getName() ) ) {
UIManager.setLookAndFeel( info.getClassName() );
break;
}
}
} catch( Exception e ) {
e.printStackTrace();
}
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setLocationRelativeTo( null );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.getContentPane().add( getJTree() );
f.pack();
f.setVisible( true );
}
private JTree getJTree() {
JTree jTree = new JTree();
jTree.setCellRenderer( new LocalRenderer() );
return jTree;
}
} );
}
private static class LocalRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasfocus ) {
DefaultTreeCellRenderer result = (DefaultTreeCellRenderer)super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasfocus );
if( true ) {
result.setFont( new JLabel().getFont() );
Icon icon = UIManager.getIcon("FileView.floppyDriveIcon");
result.setIcon( icon );
}
return(result);
}
}
}
最佳答案
编辑
“Tree.selectionBackground”键控制 JTree 上的突出显示 - 它是在树级别完成的,而不是在 TreeCellRenderer 级别(这就是管理起来有点困惑的原因)。此代码将为您提供一棵树,您可以在其中控制突出显示:
private JTree getJTree() {
JTree jTree = new JTree();
jTree.setOpaque(true);
jTree.setBackground(Color.white);
UIDefaults paneDefaults = new UIDefaults();
paneDefaults.put("Tree.selectionBackground",null);
JTextPane pane = new JTextPane();
jTree.putClientProperty("Nimbus.Overrides",paneDefaults);
jTree.putClientProperty("Nimbus.Overrides.InheritDefaults",false);
jTree.setCellRenderer( new LocalRenderer() );
return jTree;
}
这里是将突出显示更改为红色的示例。请注意,图标的背景也将突出显示 - 这也是非 nimbus L&F 的默认行为。如果您不想突出显示图标,则必须使用比默认 JLabel 更高级的东西来呈现 TreeCell:
public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasfocus ) {
DefaultTreeCellRenderer result = (DefaultTreeCellRenderer)super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasfocus );
result.setOpaque(true);
if( true ) {
result.setFont( new JLabel().getFont() );
Icon icon = UIManager.getIcon("FileView.floppyDriveIcon");
result.setIcon( icon );
}
if(sel){
result.setBackground(Color.red);
} else{
result.setBackground(Color.white);
}
return(result);
}
原始答案
解决此问题的最简单方法之一是将选定的背景颜色设置为透明。问题是它试图绘制标签的背景——它没有 JTree 的选择使用的酷 Nimbus 画家。所以将这一行添加到 getTreeCellRendererComponent 方法中:
result.setBackgroundSelectionColor(new Color(0,0,0,0));
另一种选择是使用 nimbus painter 作为 TreeCellRenderer 的背景——但在这种情况下这似乎有点矫枉过正。
关于java - 更改 Nimbus LaF 处理 JTree 节点突出显示的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10340071/
如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我尝试使用不同的ssh_options在同一阶段运行capistranov.3任务。我的production.rb说:set:stage,:productionset:user,'deploy'set:ssh_options,{user:'deploy'}通过此配置,capistrano与用户deploy连接,这对于其余的任务是正确的。但是我需要将它连接到服务器中配置良好的an_other_user以完成一项特定任务。然后我的食谱说:...taskswithoriginaluser...task:my_task_with_an_other_userdoset:user,'an_othe
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article