⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontchooserwithpole.java

📁 简单的qq聊天室!!!!!!!!!!!!!!!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			attributes.put(SUPERSCRIPT, SUPERSCRIPT_SUPER);		superscriptCheckBox.setEnabled(!subscriptCheckBox.isSelected());		subscriptCheckBox.setEnabled(!superscriptCheckBox.isSelected());		Font fn = new Font(attributes);		previewLabel.setText(previewText.toString());		previewLabel.setFont(fn);		Color c = (Color) colorComboBox.getSelectedItem();		previewLabel.setForeground(c);		previewLabel.repaint();	}	public static void main(String argv[]) {		GraphicsEnvironment ge = GraphicsEnvironment				.getLocalGraphicsEnvironment();		fontNames = ge.getAvailableFontFamilyNames();		fontSizes = new String[] { "8", "9", "10", "11", "12", "14", "16",				"18", "20", "22", "24", "26", "28", "36", "48", "72" };		FontChooserWithPole dlg = new FontChooserWithPole(new JFrame());		SimpleAttributeSet a = new SimpleAttributeSet();		StyleConstants.setFontFamily(a, "Monospaced");		StyleConstants.setFontSize(a, 12);		dlg.setAttributes(a);		dlg.setVisible(true);	}}class InputList extends JPanel implements ListSelectionListener, ActionListener {	protected JLabel label = new JLabel();	protected JTextField textfield;	protected JList list;	protected JScrollPane scroll;	public InputList(String[] data, String title) {		setLayout(null);		add(label);		textfield = new OpelListText();		textfield.addActionListener(this);		label.setLabelFor(textfield);		add(textfield);		list = new OpelListList(data);		list.setVisibleRowCount(4);		list.addListSelectionListener(this);		scroll = new JScrollPane(list);		add(scroll);	}	public InputList(String title, int numCols) {		setLayout(null);		label = new OpelListLabel(title, JLabel.LEFT);		add(label);		textfield = new OpelListText(numCols);		textfield.addActionListener(this);		label.setLabelFor(textfield);		add(textfield);		list = new OpelListList();		list.setVisibleRowCount(4);		list.addListSelectionListener(this);		scroll = new JScrollPane(list);		add(scroll);	}	public void setToolTipText(String text) {		super.setToolTipText(text);		label.setToolTipText(text);		textfield.setToolTipText(text);		list.setToolTipText(text);	}	public void setDisplayedMnemonic(char ch) {		label.setDisplayedMnemonic(ch);	}	public void setSelected(String sel) {		list.setSelectedValue(sel, true);		textfield.setText(sel);	}	public String getSelected() {		return textfield.getText();	}	public void setSelectedInt(int value) {		setSelected(Integer.toString(value));	}	public int getSelectedInt() {		try {			return Integer.parseInt(getSelected());		} catch (NumberFormatException ex) {			return -1;		}	}	public void valueChanged(ListSelectionEvent e) {		Object obj = list.getSelectedValue();		if (obj != null)			textfield.setText(obj.toString());	}	public void actionPerformed(ActionEvent e) {		ListModel model = list.getModel();		String key = textfield.getText().toLowerCase();		for (int k = 0; k < model.getSize(); k++) {			String data = (String) model.getElementAt(k);			if (data.toLowerCase().startsWith(key)) {				list.setSelectedValue(data, true);				break;			}		}	}	public void addListSelectionListener(ListSelectionListener lst) {		list.addListSelectionListener(lst);	}	public Dimension getPreferredSize() {		Insets ins = getInsets();		Dimension labelSize = label.getPreferredSize();		Dimension textfieldSize = textfield.getPreferredSize();		Dimension scrollPaneSize = scroll.getPreferredSize();		int w = Math.max(Math.max(labelSize.width, textfieldSize.width),				scrollPaneSize.width);		int h = labelSize.height + textfieldSize.height + scrollPaneSize.height;		return new Dimension(w + ins.left + ins.right, h + ins.top + ins.bottom);	}	public Dimension getMaximumSize() {		return getPreferredSize();	}	public Dimension getMinimumSize() {		return getPreferredSize();	}	public void doLayout() {		Insets ins = getInsets();		Dimension size = getSize();		int x = ins.left;		int y = ins.top;		int w = size.width - ins.left - ins.right;		int h = size.height - ins.top - ins.bottom;		Dimension labelSize = label.getPreferredSize();		label.setBounds(x, y, w, labelSize.height);		y += labelSize.height;		Dimension textfieldSize = textfield.getPreferredSize();		textfield.setBounds(x, y, w, textfieldSize.height);		y += textfieldSize.height;		scroll.setBounds(x, y, w, h - y);	}	public void appendResultSet(ResultSet results, int index,			boolean toTitleCase) {		textfield.setText("");		DefaultListModel model = new DefaultListModel();		try {			while (results.next()) {				String str = results.getString(index);				if (toTitleCase) {					str = Character.toUpperCase(str.charAt(0))							+ str.substring(1);				}				model.addElement(str);			}		} catch (SQLException ex) {			System.err.println("appendResultSet: " + ex.toString());		}		list.setModel(model);		if (model.getSize() > 0)			list.setSelectedIndex(0);	}	class OpelListLabel extends JLabel {		public OpelListLabel(String text, int alignment) {			super(text, alignment);		}		public AccessibleContext getAccessibleContext() {			return InputList.this.getAccessibleContext();		}	}	class OpelListText extends JTextField {		public OpelListText() {		}		public OpelListText(int numCols) {			super(numCols);		}		public AccessibleContext getAccessibleContext() {			return InputList.this.getAccessibleContext();		}	}	class OpelListList extends JList {		public OpelListList() {		}		public OpelListList(String[] data) {			super(data);		}		public AccessibleContext getAccessibleContext() {			return InputList.this.getAccessibleContext();		}	}	// Accessibility Support	public AccessibleContext getAccessibleContext() {		if (accessibleContext == null)			accessibleContext = new AccessibleOpenList();		return accessibleContext;	}	protected class AccessibleOpenList extends AccessibleJComponent {		public String getAccessibleName() {			System.out.println("getAccessibleName: " + accessibleName);			if (accessibleName != null)				return accessibleName;			return label.getText();		}		public AccessibleRole getAccessibleRole() {			return AccessibleRole.LIST;		}	}}class FontLabel extends JLabel {	public FontLabel(String text) {		super(text, JLabel.CENTER);		setBackground(Color.white);		setForeground(Color.black);		setOpaque(true);		setBorder(new LineBorder(Color.black));		setPreferredSize(new Dimension(120, 40));	}}class ColorComboBox extends JComboBox {	public ColorComboBox() {		int[] values = new int[] { 0, 128, 192, 255 };		for (int r = 0; r < values.length; r++)			for (int g = 0; g < values.length; g++)				for (int b = 0; b < values.length; b++) {					Color c = new Color(values[r], values[g], values[b]);					addItem(c);				}		setRenderer(new ColorComboRenderer1());	}	class ColorComboRenderer1 extends JPanel implements ListCellRenderer {		protected Color m_c = Color.black;		public ColorComboRenderer1() {			super();			setBorder(new CompoundBorder(new MatteBorder(2, 10, 2, 10,					Color.white), new LineBorder(Color.black)));		}		public Component getListCellRendererComponent(JList list, Object obj,				int row, boolean sel, boolean hasFocus) {			if (obj instanceof Color)				m_c = (Color) obj;			return this;		}		public void paint(Graphics g) {			setBackground(m_c);			super.paint(g);		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -