0
다음 스 니펫을 사용하여 대화방을 만듭니다.수정 된 JScrollPane의 JEditorPane 배경 이미지
chatlog = new JEditorPane("text/html", "<html>") {
private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g) {
// set background green - but can draw image here too
g.setColor(new Color(0,0,0,0));
g.fillRect(0, 0, getWidth(), getHeight());
// uncomment the following to draw an image
Image img;
try {
img = ImageIO.read(new File("images/chatlog.png"));
g.drawImage(img, 0, 0, this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.paintComponent(g);
}
};
chatlog.setFont(new Font("Segoe UI", Font.PLAIN, 14));
chatlog.setEditable(false);
chatlog.setOpaque(false);
chatScroll = new JScrollPane(chatlog);
chatScroll.setBounds(4, 454, 620, 100);
chatScroll.setOpaque(false);
chatScroll.setBackground(new Color(0,0,0,0));
chatScroll.setBorder(BorderFactory.createEmptyBorder());
chatScroll.setVisible(false);
JEditorPane에서 배경 이미지를 사용합니다. 그러나 많은 내용을 채팅 로그에 쓰면 배경 이미지가 텍스트와 함께 위로 이동합니다.
도와 주시겠습니까?
관련이없는
는 : 적, 구성 요소의 수동 크기/위치 결정을하지 않는다 - 그 LayoutManager에의 독점적 인 책임입니다. – kleopatra
관련 : 예, 편집기의 맨 위에 그릴 때 다른 작업을 수행해야합니다 :-) 전체 배율을 채우기 위해 배율을 조정하거나 (약간 이상하게 보일 수도 있음) viewPort의 배경으로 칠하십시오. – kleopatra