Java自定义Matlab按钮外观 [英] Custom Matlab pushbutton appearance with Java

查看:111
本文介绍了Java自定义Matlab按钮外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Java更改Matlab按钮的外观.为此,我使用了应用程序 Findjobj .但是,由于我不懂Java,因此我无法正确使用Java类,因此我需要使按钮带有圆角.根据此处)找到的信息,我尝试设置设置类BorderFactory的按钮:

I want to change the appearance of a Matlab pushbutton with Java. For it, I use the application Findjobj. However, because of I do not know Java, I have troubles to use Java classes properly that I need to get my button has rounded corners. Based on the information found here), I have tried to set up the button with the class BorderFactory:

hButton = uicontrol('string','click me!');
jButton = findjobj(hButton);
jButton.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton.setBorder(BorderFactory.createLineBorder(red,1,true));

但这不起作用.我收到以下错误消息:

But this does not work. I got the following error message:

??? Undefined function or variable 'red'.

    Error in ==> de at 4
    jButton.setBorder(BorderFactory.createLineBorder(red,1,true));

编辑:我意识到我忘了包括color和LineBorder的Java类.修复后,代码如下:

I realize I forgot to include the Java classes for color and LineBorder. After fixing it, the code looks like this:

import java.awt.Color;
import javax.swing.border.LineBorder;
hButton = uicontrol('Style','pushbutton','String','click me!',...
    'Units','normalized','Position',[0.156 0.64 0.688 0.1],'FontSize',9,...
    'ForegroundColor','w','BackgroundColor','k');
jButton = findjobj(hButton);
jButton.setCursor(java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton.setBorder(LineBorder(Color.white,5,true));

但是,结果仍然令我不满意. 此处是最终外观.我可以把角落弄圆.

However, the result still be unpleased for me. Here is the final appearance. I can get the corners to be rounded.

推荐答案

如果要使用四舍五入按钮,则必须使用此处所示)和javax.swing.plaf.synth.SynthLookAndFeel,在此处所示,但是您需要确定是否值得付出努力.

If you want rounded buttons, you'll have to use a Look & Feel whose button UI delegate draws rounded buttons. Examples include com.apple.laf.AquaButtonUI, illustrated here, and javax.swing.plaf.synth.SynthLookAndFeel, shown here. You can also implement your own ButtonUI and Border, as shown here, but you'll have decide if it's worth the effort.

附录:查看与此相关的Matlab 问题和相关的Swing

Addendum: Looking at this related Matlab question and the relevant Swing tutorial, note that "If you are going to set the L&F, you should do it as the very first step in your application."

这篇关于Java自定义Matlab按钮外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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