我正在尋找解決方案/替代我的JButton問題。我的buttontext與我的「鍵盤鍵圖片」不匹配。文本有點太低..JButton移動文本
JToggleButton tglbtn_newLine = new JToggleButton("0");
tglbtn_newLine.setBackground(new Color(240,240,240));
tglbtn_newLine.setBorderPainted(false);
tglbtn_newLine.setIcon(new ImageIcon(/*Picture of a key*/);
//should be 2..3 pix above the CENTER position:
tglbtn_newLine.setVerticalTextPosition(SwingConstants.CENTER);
tglbtn_newLine.setHorizontalTextPosition(SwingConstants.CENTER);
GridBagConstraints gbc_tglbtn_newLine = new GridBagConstraints();
gbc_tglbtn_newLine.insets = new Insets(0, 0, 5, 5);
tglbtn_newLine.setMargin(new Insets(-2, -2, -2, -2));
gbc_tglbtn_newLine.gridx = 4;
gbc_tglbtn_newLine.gridy = 5;
controlPanel.add(tglbtn_newLine, gbc_tglbtn_newLine);
是否有可能將文本設置爲特定的y位置。
示例圖:
我沒有看到問題。張貼您的SSCCE(http://sscce.org)來證明問題。 – camickr 2011-04-04 15:03:15