java按钮背景图片上文字的问题
为什么背景图片把文字挤到旁边去了呀?不是“背景”图片吗?在线等!!谢啦!菜鸟所以麻烦解释详细些。附部分代码:jbs=newJButton[24];ImageIconima...
为什么背景图片把文字挤到旁边去了呀?不是“背景”图片吗?在线等!!谢啦!菜鸟所以麻烦解释详细些。
附部分代码:
jbs=new JButton[24];
ImageIcon image = new ImageIcon("1.gif");
ImageIcon image2 = new ImageIcon("2.gif");
String[] strs={"1","2","3","4","5","6","7","8","9","0","+/-",".","/","sqrt","㏑","*","sin","←","-","cos","CE","+","y^2","="};
for(int i=0; i<12; i++){
jbs[i]=new JButton(strs[i],image);
jbs[i].setContentAreaFilled(false);
jbs[i].setMargin(new Insets(0,0,0,0));
jbs[i].setBorderPainted(false);
jbs[i].setBorder(BorderFactory.createRaisedBevelBorder());
jbs[i].setFont(new java.awt.Font("华文行楷", 3, 20));
}
for(int i=12; i<24; i++){
jbs[i]=new JButton(strs[i],image2);
jbs[i].setContentAreaFilled(false);
jbs[i].setMargin(new Insets(0,0,0,0));
jbs[i].setBorderPainted(false);
jbs[i].setBorder(BorderFactory.createRaisedBevelBorder());
jbs[i].setFont(new java.awt.Font("华文行楷", 3, 20));
} 展开
附部分代码:
jbs=new JButton[24];
ImageIcon image = new ImageIcon("1.gif");
ImageIcon image2 = new ImageIcon("2.gif");
String[] strs={"1","2","3","4","5","6","7","8","9","0","+/-",".","/","sqrt","㏑","*","sin","←","-","cos","CE","+","y^2","="};
for(int i=0; i<12; i++){
jbs[i]=new JButton(strs[i],image);
jbs[i].setContentAreaFilled(false);
jbs[i].setMargin(new Insets(0,0,0,0));
jbs[i].setBorderPainted(false);
jbs[i].setBorder(BorderFactory.createRaisedBevelBorder());
jbs[i].setFont(new java.awt.Font("华文行楷", 3, 20));
}
for(int i=12; i<24; i++){
jbs[i]=new JButton(strs[i],image2);
jbs[i].setContentAreaFilled(false);
jbs[i].setMargin(new Insets(0,0,0,0));
jbs[i].setBorderPainted(false);
jbs[i].setBorder(BorderFactory.createRaisedBevelBorder());
jbs[i].setFont(new java.awt.Font("华文行楷", 3, 20));
} 展开
4个回答
展开全部
同问题,找了好久终于解决了。当你设置好Button的文本和背景图后,在你的按钮控件代码中加上btnNewButton.setHorizontalTextPosition(SwingConstants.CENTER);注意!!!btnNewButton是我按钮的实例化对象名,用这个指令时把你的实例化按钮对象名替换了btnNewButton就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个是swing吧。。。先弄图片在弄文字不然会覆盖掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要不自己实现一个JButton的子类,要不是用swingx里的JXButton(setBackgroundPainter方法)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询