下面列出了怎么用javax.swing.plaf.LayerUI的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
ObjectInputStream.GetField f = s.readFields();
view = (V) f.get("view", null);
glassPane = (JPanel) f.get("glassPane", null);
eventMask = f.get("eventMask", 0l);
if (eventMask != 0) {
eventController.updateAWTEventListener(0, eventMask);
}
LayerUI<V> newLayerUI = (LayerUI<V>) f.get("layerUI", null);
if (newLayerUI != null) {
setUI(newLayerUI);
}
}
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
ObjectInputStream.GetField f = s.readFields();
view = (V) f.get("view", null);
glassPane = (JPanel) f.get("glassPane", null);
eventMask = f.get("eventMask", 0l);
if (eventMask != 0) {
eventController.updateAWTEventListener(0, eventMask);
}
LayerUI<V> newLayerUI = (LayerUI<V>) f.get("layerUI", null);
if (newLayerUI != null) {
setUI(newLayerUI);
}
}
@SuppressWarnings({"unchecked", "rawtypes"})
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI<?> ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
public TweenOutputSettingsPanel() {
super(new GridBagLayout());
numSecondsTF.setName("numSecondsTF");
fpsTF.setName("fpsTF");
numFramesLabel.setName("numFramesLabel");
// A single TFValidationLayerUI for all the textfields.
LayerUI<JTextField> tfLayerUI = new TFValidationLayerUI(this);
var gbh = new GridBagHelper(this);
addOutputTypeSelector(gbh);
addAnimationLengthSelector(tfLayerUI, gbh);
addInterpolationSelector(gbh);
addPingPongSelector(gbh);
addFileSelector(tfLayerUI, gbh);
}
private void addAnimationLengthSelector(LayerUI<JTextField> tfLayerUI,
GridBagHelper gbh) {
gbh.addLabelAndControl("Number of Seconds:",
new JLayer<>(numSecondsTF, tfLayerUI));
KeyListener keyListener = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent keyEvent) {
updateCalculations();
}
};
numSecondsTF.addKeyListener(keyListener);
gbh.addLabelAndControl("Frames per Second:",
new JLayer<>(fpsTF, tfLayerUI));
fpsTF.addKeyListener(keyListener);
updateCalculations();
gbh.addLabelAndControl("Number of Frames:", numFramesLabel);
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
if (source instanceof Component) {
Component component = (Component) source;
while (component != null) {
if (component instanceof JLayer) {
JLayer l = (JLayer) component;
LayerUI ui = l.getUI();
if (ui != null &&
isEventEnabled(l.getLayerEventMask(), event.getID()) &&
(!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l);
}
}
component = component.getParent();
}
}
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
private static void createAndShowGui() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
Toolkit.getDefaultToolkit().beep();
}
TabTransferHandler handler = new TabTransferHandler();
JCheckBoxMenuItem check = new JCheckBoxMenuItem("Ghost image: Heavyweight");
check.addActionListener(e -> {
JCheckBoxMenuItem c = (JCheckBoxMenuItem) e.getSource();
handler.setDragImageMode(c.isSelected() ? DragImageMode.HEAVYWEIGHT : DragImageMode.LIGHTWEIGHT);
});
JMenu menu = new JMenu("Debug");
menu.add(check);
JMenuBar menuBar = new JMenuBar();
menuBar.add(menu);
LayerUI<DnDTabbedPane> layerUI = new DropLocationLayerUI();
JFrame frame = new JFrame("@[email protected]");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(new MainPanel(handler, layerUI));
frame.setJMenuBar(menuBar);
frame.pack();
frame.setLocationRelativeTo(null);
Point pt = frame.getLocation();
pt.translate(360, 60);
JFrame sub = new JFrame("sub");
sub.getContentPane().add(new MainPanel(handler, layerUI));
sub.pack();
sub.setLocation(pt);
frame.setVisible(true);
sub.setVisible(true);
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}
bug7068740() {
super();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
DefaultTableModel model = new DefaultTableModel() {
@Override
public int getRowCount() {
return 20;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int row, int column) {
return "(" + row + "," + column + ")";
}
};
table = new JTable(model);
table.setRowSelectionInterval(0, 0);
LayerUI<JComponent> layerUI = new LayerUI<>();
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
JScrollPane scrollPane = new JScrollPane(layer);
add(scrollPane);
pack();
setLocationRelativeTo(null);
}
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JFrame frame = new JFrame("testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JEditorPane editorPane = new JEditorPane();
String str = "hello\n";
for(int i = 0; i<5; i++) {
str += str;
}
editorPane.setText(str);
JLayer<JEditorPane> editorPaneLayer = new JLayer<JEditorPane>(editorPane);
LayerUI<JComponent> layerUI = new LayerUI<JComponent>();
editorPaneLayer.setUI(layerUI);
scrollPane = new JScrollPane(editorPaneLayer);
scrollPane.setPreferredSize(new Dimension(200, 250));
frame.add(scrollPane);
frame.setSize(200, 200);
frame.pack();
frame.setVisible(true);
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) {
throw new RuntimeException("Wrong component's width!");
}
}
});
}