能不能让一个字符串每个单词拥有不同的颜色?
比如"hello world haha!"
让hello成为红色world成为绿色haha不变呢

解决方案 »

  1.   

    整三个JLabel标签就可以了:
      JLabel jLabel1 = new JLabel();
      JLabel jLabel2 = new JLabel();
      JLabel jLabel3 = new JLabel();    jLabel1.setText("hello");
        jLabel1.setForeground(new Color(255,0,0));
        jLabel1.setBounds(new Rectangle(37, 69, 26, 38));
        this.setLocale(java.util.Locale.getDefault());
        this.getContentPane().setLayout(null);
        jLabel2.setBounds(new Rectangle(70, 69, 37, 38));
        jLabel2.setForeground(Color.green);
        jLabel2.setText("world");
        jLabel3.setBounds(new Rectangle(110, 69, 35, 38));
        jLabel3.setForeground(Color.blue);
        jLabel3.setRequestFocusEnabled(true);
        jLabel3.setText("haha!");