下面列出了javax.swing.JList#setFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JList<Object> createList(List<Object> objs) {
JList<Object> list = new JList<>();
list.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
DefaultListModel<Object> lm = new DefaultListModel<>();
for (Object o : objs) {
if (o instanceof Integer) {
lm.addElement(new IntType((int) o));
} else {
lm.addElement(o);
}
}
list.setModel(lm);
return list;
}
private void initUI(Component parent)
{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(474, 225);
setLocationRelativeTo(parent);
setUndecorated(true);
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.DARK_GRAY);
contentPane.setBorder(new LineBorder(new Color(128, 128, 128), 2));
setContentPane(contentPane);
contentPane.setLayout(new MigLayout("", "[255.00,grow][106.00,grow][grow]", "[][grow][]"));
WindowDragListener wdl = new WindowDragListener(50);
addMouseListener(wdl);
addMouseMotionListener(wdl);
JLabel lblTitle = new JLabel("Select a Group");
lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblTitle.setForeground(Color.WHITE);
contentPane.add(lblTitle, "gapx 15 0, cell 0 0");
CloseButton btnClose = new CloseButton(this, JFrame.DISPOSE_ON_CLOSE);
contentPane.add(btnClose, "cell 2 0,alignx right,gapx 0 15");
JScrollPane devicesScrollPane = new JScrollPane();
devicesScrollPane.setBorder(null);
devicesScrollPane.getHorizontalScrollBar().setUI(new ModernScrollBarUI());
devicesScrollPane.getVerticalScrollBar().setUI(new ModernScrollBarUI());
contentPane.add(devicesScrollPane, "cell 0 1 3 1,grow");
groupsModel = new DefaultListModel<String>();
JList<String> listGroups = new JList<String>(groupsModel);
listGroups.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listGroups.setFont(new Font("Tahoma", Font.PLAIN, 20));
listGroups.setBackground(Color.DARK_GRAY);
listGroups.setBorder(new LineBorder(Color.GRAY));
listGroups.setForeground(Color.WHITE);
devicesScrollPane.setViewportView(listGroups);
JButton btnCreateGroup = new ModernButton("Delete Group");
btnCreateGroup.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
deleteGroup(listGroups.getSelectedValue());
}
});
contentPane.add(btnCreateGroup, "cell 2 2");
}
private JList<String> logFilesList() {
file = new File(System.getProperty("user.dir") + File.separator + "Logging Store/");
final JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(file);
fileChooser.setMultiSelectionEnabled(true);
final DefaultListModel<String> model = new DefaultListModel<String>();
final JList<String> list = new JList<String>(model);
list.setPreferredSize(new Dimension(85, 480));
list.setFont(new Font("Dialog", Font.PLAIN, 12));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
list.setFixedCellHeight(18);
list.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
selectedItem = list.getSelectedValue();
getSelectedFileName();
}
}
});
list.setCellRenderer(new LogRecordsListRenderer());
File[] selectedFiles = fileChooser.getCurrentDirectory().listFiles();
for (File f : selectedFiles) {
if (f.getName().indexOf(".log") != -1) {
model.addElement(f.getName());
}else {
continue;
}
}
if(model.isEmpty()) {
model.addElement("List is empty!");
}
return list;
}
private static<T> void setListProperties(JList<T> list) {
list.setOpaque(false);
list.setBackground(ColorPalette.DARK_BACKGROUND_COLOR);
list.setForeground(ColorPalette.FOREGROUND_COLOR);
list.setFont(Fonts.FONT);
}
KeywordsListPane(final KeywordPanelB keywordPanel) throws IOException {
JList<Keyword> list = new JList<>(KeywordsHelper.getKeywords());
list.setLayoutOrientation(JList.VERTICAL_WRAP);
list.setVisibleRowCount(-1);
list.setOpaque(false);
list.setCellRenderer(new KeywordsListCellRenderer());
list.setForeground(Color.WHITE);
list.setFont(list.getFont().deriveFont(14f));
list.addListSelectionListener((e) -> {
final Keyword keyword = list.getSelectedValue();
keywordPanel.setKeyword(keyword);
});
list.setSelectedIndex(0);
setViewportView(list);
setOpaque(false);
getViewport().setOpaque(false);
}
public YogaCombinationsView(String title, YogaResults yogaResults, PlanetaryInfo planetaryInfo) {
super(viewSize, viewLoc);
this.planetaryInfo = planetaryInfo;
this.yogaResults = yogaResults;
JPanel yogaPanel = new JPanel();
yogaList = new JList(yogaResults.getYogas().toArray());
yogaList.setFont(UIUtil.getFont("Tahoma", Font.PLAIN, 11));
yogaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
yogaList.setSelectedIndex(0);
yogaPanel.add(yogaList);
yogaPanel.setPreferredSize(yogaSize);
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, yogaPanel, createResultPane());
yogaPanel.setBorder(BorderFactory.createEtchedBorder());
splitPane.setBorder(BorderFactory.createEmptyBorder());
yogaList.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
//splitPane.remove(chartPanel);
yogaChanged((YogaResults.Result)yogaList.getSelectedValue());
//splitPane.add(chartPanel);
}
});
add(splitPane,BorderLayout.CENTER);
}
public VargaChartView(String title, PlanetaryInfo planetaryInfo) {
super(title, viewSize);
this.planetaryInfo = planetaryInfo;
JPanel vargaPanel = new JPanel();
final JList vargaList = new JList(Varga.values());
vargaList.setFont(UIUtil.getFont("Tahoma", Font.PLAIN, 11));
vargaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
vargaList.setSelectedIndex(0);
vargaPanel.add(vargaList);
vargaPanel.setPreferredSize(vargaSize);
chartPanel = new JPanel(new BorderLayout());
chartPanel.add(new Chart(new PlanetChartData(Varga.Bhava, planetaryInfo), chartSize), BorderLayout.CENTER);
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, vargaPanel, chartPanel);
vargaPanel.setBorder(BorderFactory.createEtchedBorder());
splitPane.setBorder(BorderFactory.createEtchedBorder());
chartPanel.setBorder(BorderFactory.createEmptyBorder());
vargaList.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e) {
splitPane.remove(chartPanel);
vargaChanged((Varga)vargaList.getSelectedValue());
splitPane.add(chartPanel);
}
});
add(splitPane,BorderLayout.CENTER);
}