你好每一个请帮助我, 我想
,我想在我的聊天应用程序中添加聊天表示,以使UI 样式消息冒泡演讲对话所以我想通过Java代码绘制这样的enter image description here请帮助我的代码或如何通过这样的java代码绘制, 我在https://stackoverflow.com/的第一篇文章 谢谢
答案 0 :(得分:0)
从你的问题和你在这里的时间判断,我认为你对java不太熟悉(我的意思是没有冒犯)。
相反,你可以像我一样做,这对于这种情况非常好:
我创建了一个JLabel,并为其分配了一个ImageIcon。在下面的代码示例中,您将看到我创建了两个标签,其中哪些用作按钮,一个向上箭头和一个用于列表的向下箭头:
private void buildPair() {
//Make an ImageIcon Array (optional)
ImageIcon image[] = new ImageIcon[2];
//You create a new ImageIcon with the picture from your recouses, then you the the image and scale it, in this case its scaled to 20 by 20 pixel
Image originalDown = new ImageIcon(ExtendedList.class.getResource("/Elements/Down Arrow Button.png")).getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
Image originalUp = new ImageIcon(ExtendedList.class.getResource("/Elements/Up Arrow Button.png")).getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT);
//Then I add the scaled images to a new ImageIcon and then add it to my ImageIgon arrat
image[0] = new ImageIcon(originalDown);
image[1] = new ImageIcon(originalUp);
//Using an external Jlabel array i assing it with new Jlabel with this ImageIcon
buttonPair[0] = new JLabel(image[0]);
//I then add a custom event class, but you can make your own method or leave this out if its not needed
buttonPair[0].addMouseListener(events);
//And lastly i add this to my form
this.add(buttonPair[0]);
//and repeat for as many times as you need
buttonPair[1] = new JLabel(image[1]);
buttonPair[1].addMouseListener(events);
this.add(buttonPair[1]);
}
不要忘记导入:
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;