女青年与西西
2017-09-20 13:08
采纳率: 25.8%
浏览 1.4k

急急急~~为什么java设置button,没有颜色,mac系统

package view;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class Gui extends JFrame {

    private static final long serialVersionUID = 1L;

    public Gui()
    {
        JFrame frame = new JFrame("miniCAD");
        JPanel panelBig = new JPanel();
        JPanel panelSmall  = new JPanel();
        JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelBig, panelSmall);            
        panelBig.setBackground(Color.white);
        panelSmall.setBackground(Color.white);
        pane.setRightComponent(panelSmall);
        pane.setLeftComponent(panelBig);    
        pane.setContinuousLayout(true);
        pane.setOneTouchExpandable(true);
//      Container C = frame.getContentPane();
//      C.add(pane);
        frame.add(pane);
//添加图形              
        JButton buttoncircle = new JButton("circle");
        JButton buttonline = new JButton("line");
        JButton buttonrectangle = new JButton("rectangle");
        JButton buttontext = new JButton("text");
        JButton buttontriangle = new JButton("triangle");

        control.Control monitor = new control.Control();

        panelSmall.setLayout(new GridLayout(6,1,0,0));      
        panelSmall.add(buttoncircle);
        panelSmall.add(buttonline);
        panelSmall.add(buttonrectangle);
        panelSmall.add(buttontext);
        panelSmall.add(buttontriangle);


//监听使用哪个图形      
        buttoncircle.addActionListener(monitor);
        buttonline.addActionListener(monitor);
        buttonrectangle.addActionListener(monitor);
        buttontext.addActionListener(monitor);
        buttontriangle.addActionListener(monitor);  

//添加颜色板       
        JPanel colorpane = new JPanel();
        panelSmall.add(colorpane);
        colorpane.setLayout(new GridLayout(3,3));
        JButton buttonred = new JButton();
        buttonred.setForeground(Color.red);

        buttonred.setOpaque(true);
        colorpane.add(buttonred);
        JButton buttonblack = new JButton();
        buttonblack.setBackground(Color.black);

        buttonblack.setOpaque(true);
        colorpane.add(buttonblack);
        JButton buttonblue = new JButton();
        buttonblue.setBackground(Color.blue);

        buttonblue.setOpaque(true);
        colorpane.add(buttonblue);
        JButton buttongreen = new JButton();
        buttongreen.setBackground(Color.green);
        buttongreen.setOpaque(true);
        colorpane.add(buttongreen);
        JButton buttongray = new JButton();
        buttongray.setBackground(Color.gray);
        buttongray.setOpaque(true);
        colorpane.add(buttongray);
        JButton buttonwhite = new JButton();
        buttonwhite.setBackground(Color.white);
        buttonwhite.setOpaque(true);
        colorpane.add(buttonwhite);
        JButton buttonyellow = new JButton();
        buttonyellow.setBackground(Color.yellow);
        buttonyellow.setOpaque(true);
        colorpane.add(buttonyellow);
        JButton buttonpink = new JButton();
        buttonpink.setBackground(Color.pink);
        buttonpink.setOpaque(true);
        colorpane.add(buttonpink);
        JButton buttonorange = new JButton();
        buttonorange.setBackground(Color.orange);
        buttonorange.setOpaque(true);
        colorpane.add(buttonorange);

//添加颜色监听器
//      buttonred.addActionListener(l);



        frame.setVisible(true);                 
    }

    public static void main(String[] args) {        
        Gui picture = new Gui();        
    }
}

代码之前在windows是完全可以的
现在已经按照网上搜索方法加了opaque,还是不显示颜色

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • devmiao 2017-09-20 15:48
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题