📄 friendlistcell.java
字号:
import java.awt.GridBagLayout;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.BorderFactory;
import java.awt.event.*;
public class FriendListCell extends JPanel implements ListCellRenderer{
private static final long serialVersionUID = 1L;
private JLabel head = null;
private JLabel nickname = null;
/**
* This is the default constructor
*/
public FriendListCell() {
super();
initialize();
}
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean hasCellFocus)
{
if(isSelected)
{
this.setBackground(new Color(209, 240, 254));
this.setBorder(BorderFactory.createLineBorder(Color.black, 1));
}
else
this.setBackground(Color.white);
ListCellInfo lci=(ListCellInfo)value;
this.head.setIcon(lci.getIcon());
this.nickname.setText(lci.getName());
return this;
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
nickname = new JLabel();
nickname.setText("JLabel");
FlowLayout flowLayout = new FlowLayout();
flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
head = new JLabel();
head.setText("");
head.setIcon(new ImageIcon(getClass().getResource("/head/default.png")));
this.setLayout(flowLayout);
this.setSize(177, 51);
this.add(head, null);
this.add(nickname, null);
}
}
class ListCellInfo
{
private ImageIcon head;
private String uid;
private String name;
private String logip;
private int port;
private String online;
public ListCellInfo next=null;
public ListCellInfo(){}
public ListCellInfo(ImageIcon head,String uid,String name,String logip,int port,String online)
{
this.head=head;
this.uid=uid;
this.port=port;
this.name=name;
this.logip=logip;
this.online=online;
}
public ImageIcon getIcon()
{
return this.head;
}
public String getUid()
{
return this.uid;
}
public String getName()
{
return this.name;
}
public String getLogip()
{
return this.logip;
}
public int getPort()
{
return this.port;
}
public boolean isOnline()
{
if(online.equals("在线"))
return true;
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -