当前位置: 技术问答>java相关
如何把JCHEKCBOX 加入到JLIST中
来源: 互联网 发布时间:2015-10-11
本文导语: 同题 | import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class CheckBoxList extends JFrame { protected JList m_list; protected...
同题
|
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class CheckBoxList
extends JFrame
{
protected JList m_list;
protected JLabel m_total;
public CheckBoxList()
{
super("Swing List [Check boxes]");
setSize(260, 240);
getContentPane().setLayout(new FlowLayout());
InstallData[] options = {
new InstallData("Program executable", 118),
new InstallData("Help files", 52),
new InstallData("Tools and converters", 83),
new InstallData("Source code", 133)
};
m_list = new JList(options);
CheckListCellRenderer renderer = new CheckListCellRenderer();
m_list.setCellRenderer(renderer);
m_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
CheckListener lst = new CheckListener(this);
m_list.addMouseListener(lst);
m_list.addKeyListener(lst);
JScrollPane ps = new JScrollPane();
ps.getViewport().add(m_list);
m_total = new JLabel("Space required: 0K");
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(ps, BorderLayout.CENTER);
p.add(m_total, BorderLayout.SOUTH);
p.setBorder(new TitledBorder(new EtchedBorder(),
"Please select options:") );
getContentPane().add(p);
WindowListener wndCloser = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
recalcTotal();
}
public void recalcTotal()
{
ListModel model = m_list.getModel();
int total = 0;
for (int k=0; k
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class CheckBoxList
extends JFrame
{
protected JList m_list;
protected JLabel m_total;
public CheckBoxList()
{
super("Swing List [Check boxes]");
setSize(260, 240);
getContentPane().setLayout(new FlowLayout());
InstallData[] options = {
new InstallData("Program executable", 118),
new InstallData("Help files", 52),
new InstallData("Tools and converters", 83),
new InstallData("Source code", 133)
};
m_list = new JList(options);
CheckListCellRenderer renderer = new CheckListCellRenderer();
m_list.setCellRenderer(renderer);
m_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
CheckListener lst = new CheckListener(this);
m_list.addMouseListener(lst);
m_list.addKeyListener(lst);
JScrollPane ps = new JScrollPane();
ps.getViewport().add(m_list);
m_total = new JLabel("Space required: 0K");
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(ps, BorderLayout.CENTER);
p.add(m_total, BorderLayout.SOUTH);
p.setBorder(new TitledBorder(new EtchedBorder(),
"Please select options:") );
getContentPane().add(p);
WindowListener wndCloser = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
recalcTotal();
}
public void recalcTotal()
{
ListModel model = m_list.getModel();
int total = 0;
for (int k=0; k
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!