调整图标大小以正确适合 ScrollPane 角按钮
我想将 java 的默认 QuestionIcon 添加到滚动窗格中的角按钮,但是图像不正确(因为按钮非常小)。我应该怎么做才能使图标正确显示?
这是代码,它有效,所以你可以尝试一下并亲眼看看问题:)
import javax.swing.*;
public class CornerButton extends JFrame
{
public CornerButton()
{
JTextArea area = new JTextArea(20, 20);
JScrollPane scroll = new JScrollPane(area);
JButton btn = new JButton(UIManager.getIcon("OptionPane.questionIcon"));
scroll.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, btn);
this.add(scroll);
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
CornerButton mainFrame = new CornerButton();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
mainFrame.setSize(200,200);
}
}
NB。我在 Sun 的论坛上发布了同样的问题,但没有人回答,希望我能从这里找到一些帮助:)
提前致谢。
I would like to add java's default questionIcon to a corner button in a Scrollpane, however the image doesn't fit correctly (since the button is very small). What should i do to make the icon fit correctly?
Here is the code, It works, so you can try it out and see for yourselfs the problem :)
import javax.swing.*;
public class CornerButton extends JFrame
{
public CornerButton()
{
JTextArea area = new JTextArea(20, 20);
JScrollPane scroll = new JScrollPane(area);
JButton btn = new JButton(UIManager.getIcon("OptionPane.questionIcon"));
scroll.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, btn);
this.add(scroll);
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
CornerButton mainFrame = new CornerButton();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
mainFrame.setSize(200,200);
}
}
NB. I posted the same question on Sun's forums but no one answered, hope I find some help from here :)
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不想破坏外观和感觉,您可以调整图标图像的大小并创建一个新图标,如下所示:
它看起来也不错。
If you would prefer not to violate the look and feel, you might just resize the icon image and create a new icon like this:
It looks pretty good too.
您可以尝试增加 JScrollBars 的宽度,以便按钮有更多的显示空间。例如:
You could try increasing the width of the JScrollBars so that the button has more room to be displayed. For example: