下面列出了javax.swing.JPanel#setFocusable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initializeComponents() {
graphPanel = new JPanel() {
private static final long serialVersionUID = -1105560304467720245L;
@Override
public Dimension getPreferredSize() {
return getGraphSize();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
paintGraph((Graphics2D) g, graphPanel.getWidth(), graphPanel.getHeight());
}
};
graphPanel.setFocusable(true);
}
@Override
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JPanel panel = (JPanel)value;
panel.setFocusable(false);
if (isSelected) {
panel.setForeground((Color)UIManager.get("List.selectionForeground"));
panel.setBackground((Color)UIManager.get("List.selectionBackground"));
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
}
else {
panel.setBackground(list.getBackground());
panel.setForeground(list.getForeground());
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("ContactItem.background")));
}
list.setBackground((Color)UIManager.get("ContactItem.background"));
return panel;
}
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JPanel panel = (JPanel)value;
panel.setFocusable(false);
if (isSelected) {
panel.setForeground(Color.black);
panel.setBackground(new Color(217, 232, 250));
panel.setBorder(BorderFactory.createLineBorder(new Color(187, 195, 215)));
}
else {
panel.setBackground(list.getBackground());
panel.setForeground(list.getForeground());
panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));
}
return panel;
}
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JPanel panel = (JPanel)value;
panel.setFocusable(false);
if (isSelected) {
panel.setForeground((Color)UIManager.get("List.selectionForeground"));
panel.setBackground((Color)UIManager.get("List.selectionBackground"));
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
}
else {
panel.setBackground(list.getBackground());
panel.setForeground(list.getForeground());
panel.setBorder(BorderFactory.createMatteBorder(0,0,1,0, Color.lightGray));
}
list.setBackground((Color)UIManager.get("List.background"));
return panel;
}
public PopupManager(String title) {
main = new JPanel();
main.setBorder(new javax.swing.border.TitledBorder(title));
info = new JLabel();
main.add(info);
main.setFocusable(false);
}
private void constructPanel(String[] values) {
// constructing editors
editors = new PropertyValueCellEditor[types.length];
for (int i = 0; i < types.length; i++) {
editors[i] = PropertyPanel.instantiateValueCellEditor(types[i], operator);
}
// building panel
panel = new JPanel();
panel.setFocusable(true);
panel.setLayout(new GridLayout(1, editors.length));
for (int i = 0; i < types.length; i++) {
Component editorComponent = editors[i].getTableCellEditorComponent(null, values[i], false, 0, 0);
if (editorComponent instanceof JComboBox) {
if (((JComboBox<?>) editorComponent).isEditable()) {
ComboBoxEditor editor = ((JComboBox<?>) editorComponent).getEditor();
if (editor instanceof BasicComboBoxEditor) {
editor.getEditorComponent().addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
} else if (editorComponent instanceof JPanel) {
JPanel editorPanel = (JPanel) editorComponent;
Component[] components = editorPanel.getComponents();
for (Component comp : components) {
comp.addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
panel.add(editorComponent);
panel.addFocusListener(focusListener);
}
}
public BinaryPanel(final MainPanel mainPanel) {
super(new BorderLayout());
this.mainPanel = mainPanel;
add(new JScrollPane(hexEditor), BorderLayout.CENTER);
JPanel bottomPanel = new JPanel(new BorderLayout());
JPanel buttonsPanel = new JPanel(new FlowLayout());
bottomPanel.add(buttonsPanel, BorderLayout.EAST);
add(bottomPanel, BorderLayout.SOUTH);
// todo: honfika: dynamically resize the hex data
/*addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
setBinaryData(binaryDataTag);
}
});*/
swfInsidePanel = new JPanel();
swfInsidePanel.setBackground(new Color(253, 205, 137));
swfInsidePanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
swfInsidePanel.add(new JLabel(AppStrings.translate("binarydata.swfInside")));
swfInsidePanel.setFocusable(true);
swfInsidePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
swfInsidePanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
mainPanel.loadFromBinaryTag(binaryDataTag);
swfInsidePanel.setVisible(false);
}
});
add(swfInsidePanel, BorderLayout.NORTH);
swfInsidePanel.setVisible(false);
}
public void setup() {
super.setup();
// set special window properties
jframe = (JFrame)((PSurfaceAWT.SmoothCanvas) getSurface().getNative()).getFrame();
jframe.removeNotify();
jframe.setUndecorated(true);
jframe.setLayout(null);
jframe.addNotify();
jframe.setAlwaysOnTop(true);
pg = createGraphics(width, height);
cursor = Base64Image.decodePImageFromBase64("iVBORw0KGgoAAAANSUhEUgAAAGoAAAC1CAMAAACAl5pfAAAAYFBMVEVHcEyRkZEQEBAAAAB1dXVISEgmJib///8cHBwGBgYoKCj9/f3////T09O8vLzl5eX19fVubm4yMjJCQkJXV1eJiYmhoaEvLy+YmJjY2Ng6Ojqurq7Hx8f19fXo6OheXl4dpwGJAAAAIHRSTlMAbe//ibfYBOP5//7/7u3x9vP9+fbv7s/kJcVRNwoVoJWYs8AAAAPzSURBVHgBvM2FiURRAASw+679t3uGDSwamJcG8jXUNC/LvI6YtuXfftSnaVlGXecy7LqWvPpVXv0qr36VV7vKq1/l1a7yald5tau82lVe7SqvdpVXuypcUd3P3b2iettXVO0rq/KVVfnKqnxlVb6yKl9Zla+syldW5Sur8pVV+cqqfGVVvrIqX58VX17xBRVfUNkFFVxQwQUVXFDBpRVcWsGlFVxawcWVX1755ZVfXvkFFV9Q8QUVX1DxBRVfUPEFFV9Q8QUVX1DRBRVcUMEFFVxQwQUVXFDBBRVfUPEFFV9Q8QUVX1DxBRVfUPEFFV9Q8QUVX1DxBRVfUPEFFV9Q8QUVX1DxBRVfUPEFFV9Q8QUVX1DxBRVfUPEFFV9Q8WWVX1799HIeWo6DMBTF3cBx7/3/v3L7xsqGvMXImXd62gWPuLKmZXmWFUVZam1kBc8sBqpSj3Urkrpu2raquq6Xryw3VPsA4VAWf+y2zOCIGoPr8dxQlQMqdUPl6jrKByiUL0S111GRI6q8vq3pvyiddxm+gvMQx2nq+1LK9yC5gGI/z6pSGSqMVTxl26d1WRbPC8PjiKL550riY0e2oFZQJdjWLOyCUdXfD6xNT/3NdgOqO5WKthXyUT352rcvz9bkxHBRVAmGhRTn0wsTlVFSoHpwBWMGiiza6vpO11FAB6oA24rcUdrQ+2ogQplcRwFzK9SLQ2eUMqGqf0mk3lNXFCWhbWVUhE6ompKiE5XzREhQZpJITxYwV7BfQRESXawXWInwuI5qKGmgrzCJsDnr/TKqVS+32sf7K6jJSfcuoipKSn83ot1OhOk1VEdJ/t+WN4Bt5UiEANU/kR41tTiKEKBySpJkkT4QIbmn3qxR4zuSCM9taYYIZUBjFs0WPFIxGr8EpEciTuMHKMN7pvci1KQwBmsUOI1IhKOtCKUFiSdCgArxyxrU+O1QeGV8EVIUPPNEhJ2rCKUFCYgQTEAAhct1PVEZbvwQhe6IsQjxBARQaQJQSIR4AjKgfKjmRHInIJ82KBS+CA/SNnAm7gS0+YSEE3MnoP3XJ6SAdGPjX8NwFTbx7USYCGawCOnsFzIQQISg3nmZGRMQCEOEw71/nl3jCYgf68bPT8KcgHDsRQgaP4iLCDVo/CBuIgQTEIiLCDUUoUP4ExCOXePXmi9C/gT0UREu94ow/zoRKnAFPytC3SoV3CNCPAFlNeHgW2Ve4+/Ihnhywo2/bAiIJww8AeVPHND2mSLsKhOI6oIvQpx0ETclxKB5FbdlAxx57OLORO9AsSduzmTeUAS6L1uEJH6YfPDfEJEMi/hQEskvBYd6T28tBWCnaBUfT+j/LIVNWOY7PppBCtOtd0oAAAAASUVORK5CYII=");
JPanel panel = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
protected void paintComponent(Graphics graphics) {
if (graphics instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) graphics;
g2d.drawImage(pg.image, 0, 0, null);
}
}
};
jframe.setContentPane(panel);
panel.setFocusable(true);
panel.setFocusTraversalKeysEnabled(false);
panel.requestFocus();
panel.requestFocusInWindow();
}
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JPanel panel = (JPanel)value;
panel.setFocusable(false);
if (isSelected) {
panel.setForeground(Color.white);
panel.setBackground(new Color(51, 136, 238));
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
}
else {
if (index % 2 == 0) {
panel.setBackground((Color)UIManager.get("List.selectionBackground"));
}
else {
panel.setBackground(list.getBackground());
}
panel.setForeground(list.getForeground());
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.background")));
}
list.setBackground((Color)UIManager.get("List.background"));
return panel;
}