我们可以在Java Swing中使用GTK + 2.0按钮样式吗? [英] Can we ape the GTK+ 2.0 button style in Java Swing?

查看:181
本文介绍了我们可以在Java Swing中使用GTK + 2.0按钮样式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java Swing的问题在于外观(Metal,Nimbus,GTK ......),与SWT,Windows,Mac和Gnome工具包相比最差,并且获得好看的小部件是乌托邦,但我我问这个问题。

The problem with Java Swing is the look and feels (Metal, Nimbus, GTK...), the worst out there compared to SWT, Windows, Mac and Gnome Tool Kit, and getting good looking widgets is utopist, yet I am asking the question though.

我需要知道是否有可能调整JButton看起来像默认的GTK按钮。
否则,我们可以给JButton文本一个样式(例如阴影)吗?

I need to know if there is a possibility to tweak a JButton to look like a default GTK button. Otherwise, can we give the JButton text a style (a shadow for example)?

public class myTweakedButton extends JButton {

// Override style attributes here.

}

以下是GTK应用于按钮小部件的样式:

Here is the style applied by GTK to the button widget:

style "button" {
    xthickness = 3
    ythickness = 3

    bg[NORMAL] = shade (1.07, "#cdcdcd")
    bg[PRELIGHT] = shade (1.09, "#cdcdcd")
    bg[ACTIVE] = shade (1.0, "#cdcdcd")
    bg[INSENSITIVE] = mix (0.25, @bg_color, "#e2e1e1")
    fg[INSENSITIVE] = "#9c9c9c"

    engine "murrine" {
        #contrast = 1.0
        border_shades = {1.04, 0.82}
        reliefstyle = 5
        shadow_shades = {1.02, 1.1}
        textstyle = 1
        glowstyle = 5
        glow_shade = 1.1
        #text_shade = 1.04
    }

这是使用Java引擎提供的默认GTK外观时,Button的外观如何:

This is how a Button looks like when using the default GTK Look and Feel provided by Java engine:

这里如何对接看起来像Linux(GTK 2.0)。

And here how a button looks like under Linux (GTK 2.0).

差异实际上是Java GTK LAF中的文本提示,而GTK按钮文本则采用离散阴影设置。

The difference is actually a bad text hinting in Java GTK LAF, while GTK button text is styled with a discrete shadow.

推荐答案

有两种方式

但正确的方法(不要重新发明)使用正确的外观

but correct way (don't reinvent the wheel) use proper Look and Feel,

可能的情况


  1. 转到无实质性的

  1. go to Insubstantial

下载代码来源,

导入所有课程到IDE(2-15分钟取决于PC硬件)

import all classes to the IDE (2-15 min depends of PC HardWare)

搜索文件夹 test ,那里是 Check.java

运行并且尝试 JMenu外观和/或中的所有内容,每个好的自定义Java Swing外观和感觉需要下载jar文件可以从 JMenu

run that and to try everything in JMenu Look and Feel, required download jar files for every good Custom Java Swing Look and Feels are accesible from JMenu

访问,所有标准和良好的自定义Swing的外观和感觉在一个 JFrame

nothing better around, all standard and good custom Swing's Look and Feel in one JFrame

也许更好的方法是将物质与SwingX一起使用,非常好的自定义Swing自定义实现

maybe better would be to use Substance together with SwingX, very good Custom implementation for Custom Swing, again nothing better around

注意:SwingX需要的不仅仅是基本的Swing知识,Substance(我的视图)需要更新并且还要在原始代码中自定义一些方法

NOTICE: SwingX required more than basic Swing knowledge, Substance (my view) required update and customize some methods in original code too


这篇关于我们可以在Java Swing中使用GTK + 2.0按钮样式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆