-
Bug
-
Resolution: Fixed
-
P2
-
7
-
b89
-
generic
-
generic
JDK: 7b78+
Platform: All
Method SynthTextPaneUI.installUI(JComponent c) says:
Installs the UI for a component. This does the following things:
...
2. Installs the default caret and highlighter into the associated component.
...
It doesn't happen. Please see the following example:
-----------------------------------------------------------------------------------------------------------
package synth;
import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.synth.*;
import javax.swing.text.*;
import java.awt.*;
import static java.lang.System.*;
public class Defaults {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() {
doTheTest();
}
});
}
private static void doTheTest() {
try {
UIManager.setLookAndFeel(new SynthLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
JTextPane textPane = new JTextPane();
SynthTextPaneUI ui = new SynthTextPaneUI() {
@Override
public void installUI(JComponent c) {
JTextPane textPane = (JTextPane) c;
System.out.println("textPane.getCaret() instanceof DefaultCaret = " +
(textPane.getCaret() instanceof DefaultCaret));
System.out.println("textPane.getHighlighter() instanceof DefaultHighlighter = " +
(textPane.getHighlighter() instanceof DefaultHighlighter));
super.installUI(c);
System.out.println("Method installUI called.");
System.out.println("textPane.getCaret() instanceof DefaultCaret = " +
(textPane.getCaret() instanceof DefaultCaret));
System.out.println("textPane.getHighlighter() instanceof DefaultHighlighter = " +
(textPane.getHighlighter() instanceof DefaultHighlighter));
}
};
textPane.setCaret(CARET_STUB);
textPane.setHighlighter(HIGHLIGHTER_STUB);
// the following will lead to expected behavior
// textPane.setCaret(null);
// textPane.setHighlighter(null);
textPane.setUI(ui);
}
private static final Highlighter HIGHLIGHTER_STUB = new Highlighter() {
public void install(JTextComponent c) { }
public void deinstall(JTextComponent c) { }
public void paint(Graphics g) { }
public Object addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException {return null;}
public void removeHighlight(Object tag) { }
public void removeAllHighlights() { }
public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException { }
public Highlight[] getHighlights() { return new Highlight[0]; }
};
private static final Caret CARET_STUB = new Caret() {
public void install(JTextComponent c) { }
public void deinstall(JTextComponent c) { }
public void paint(Graphics g) { }
public void addChangeListener(ChangeListener l) { }
public void removeChangeListener(ChangeListener l) { }
public boolean isVisible() { return false; }
public void setVisible(boolean v) { }
public boolean isSelectionVisible() { return false; }
public void setSelectionVisible(boolean v) { }
public void setMagicCaretPosition(Point p) { }
public Point getMagicCaretPosition() { return null; }
public void setBlinkRate(int rate) { }
public int getBlinkRate() { return 0; }
public int getDot() { return 0; }
public int getMark() { return 0; }
public void setDot(int dot) { }
public void moveDot(int dot) { }
};
}
-----------------------------------------------------------------------------------------------------------
The output will be:
textPane.getCaret() instanceof DefaultCaret = false
textPane.getHighlighter() instanceof DefaultHighlighter = false
Method installUI called.
textPane.getCaret() instanceof DefaultCaret = false
textPane.getHighlighter() instanceof DefaultHighlighter = false
Platform: All
Method SynthTextPaneUI.installUI(JComponent c) says:
Installs the UI for a component. This does the following things:
...
2. Installs the default caret and highlighter into the associated component.
...
It doesn't happen. Please see the following example:
-----------------------------------------------------------------------------------------------------------
package synth;
import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.synth.*;
import javax.swing.text.*;
import java.awt.*;
import static java.lang.System.*;
public class Defaults {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() {
doTheTest();
}
});
}
private static void doTheTest() {
try {
UIManager.setLookAndFeel(new SynthLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
JTextPane textPane = new JTextPane();
SynthTextPaneUI ui = new SynthTextPaneUI() {
@Override
public void installUI(JComponent c) {
JTextPane textPane = (JTextPane) c;
System.out.println("textPane.getCaret() instanceof DefaultCaret = " +
(textPane.getCaret() instanceof DefaultCaret));
System.out.println("textPane.getHighlighter() instanceof DefaultHighlighter = " +
(textPane.getHighlighter() instanceof DefaultHighlighter));
super.installUI(c);
System.out.println("Method installUI called.");
System.out.println("textPane.getCaret() instanceof DefaultCaret = " +
(textPane.getCaret() instanceof DefaultCaret));
System.out.println("textPane.getHighlighter() instanceof DefaultHighlighter = " +
(textPane.getHighlighter() instanceof DefaultHighlighter));
}
};
textPane.setCaret(CARET_STUB);
textPane.setHighlighter(HIGHLIGHTER_STUB);
// the following will lead to expected behavior
// textPane.setCaret(null);
// textPane.setHighlighter(null);
textPane.setUI(ui);
}
private static final Highlighter HIGHLIGHTER_STUB = new Highlighter() {
public void install(JTextComponent c) { }
public void deinstall(JTextComponent c) { }
public void paint(Graphics g) { }
public Object addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException {return null;}
public void removeHighlight(Object tag) { }
public void removeAllHighlights() { }
public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException { }
public Highlight[] getHighlights() { return new Highlight[0]; }
};
private static final Caret CARET_STUB = new Caret() {
public void install(JTextComponent c) { }
public void deinstall(JTextComponent c) { }
public void paint(Graphics g) { }
public void addChangeListener(ChangeListener l) { }
public void removeChangeListener(ChangeListener l) { }
public boolean isVisible() { return false; }
public void setVisible(boolean v) { }
public boolean isSelectionVisible() { return false; }
public void setSelectionVisible(boolean v) { }
public void setMagicCaretPosition(Point p) { }
public Point getMagicCaretPosition() { return null; }
public void setBlinkRate(int rate) { }
public int getBlinkRate() { return 0; }
public int getDot() { return 0; }
public int getMark() { return 0; }
public void setDot(int dot) { }
public void moveDot(int dot) { }
};
}
-----------------------------------------------------------------------------------------------------------
The output will be:
textPane.getCaret() instanceof DefaultCaret = false
textPane.getHighlighter() instanceof DefaultHighlighter = false
Method installUI called.
textPane.getCaret() instanceof DefaultCaret = false
textPane.getHighlighter() instanceof DefaultHighlighter = false