在面板中添加復雜圖像,在一個自定義用戶界面中使用按鈕我怎樣才能將這樣的圖像放到slavePanelJPanel的頂部和頂部,調整JButtons看起來像圖像但是按鈕正確纏繞?(現在它們形成一排,四列)在此輸入圖像描述 // // Shot Gun mover up/down/left/right, middle on is for zoom // public void GunMover(JPanel configPanel) throws IOException { // Master Panel - holds everything JPanel masterPanel = new Panel(); masterPanel.setLayout(new SpringLayout()); // Slave Panel - with image background JPanel slavePanel = new Panel(); slavePanel.setLayout(new SpringLayout()); // Row 1 final JButton ptzLeft = new JButton("<"); masterPanel.add(ptzLeft, BorderLayout.WEST); // Row 2 final JButton ptzRight = new JButton(">"); masterPanel.add(ptzRight, BorderLayout.CENTER); // Row 3 final JButton ptzUp = new JButton("^"); masterPanel.add(ptzUp, BorderLayout.WEST); // Row 4 final JButton ptzDown = new JButton("down"); masterPanel.add(ptzDown, BorderLayout.CENTER); // How do i add slavePanel this background and add all the JButtons // According to that image shape? // Layout the panel. SpringUtilities.makeCompactGrid(masterPanel, 1, 4, //rows, cols 6, 6, //initX, initY 6, 6); configPanel.setLayout(new GridLayout(0,1)); configPanel.add(masterPanel); }跟進:優秀的一個來自Andrew Thompson +至少我的破碎方法在此輸入圖像描述package test;import java.awt.*;import java.awt.font.FontRenderContext;import java.awt.font.TextLayout;import javax.swing.*;public class New extends JFrame { private static final long serialVersionUID = 1L; private ImageIcon errorIcon = (ImageIcon) UIManager.getIcon("OptionPane.errorIcon"); private Icon infoIcon = UIManager.getIcon("OptionPane.informationIcon"); private Icon warnIcon = UIManager.getIcon("OptionPane.warningIcon");
添加回答
舉報
0/150
提交
取消