本文整理汇总了Java中javax.swing.JEditorPane.getBackground方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.getBackground方法的具体用法?Java JEditorPane.getBackground怎么用?Java JEditorPane.getBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.getBackground方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setEditable
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void setEditable(boolean b) {
JEditorPane editor = editor();
if (editor.isEditable() == b) return;
editor.setEditable(b);
if (b) {
if (lastBgColor != null) editor.setBackground(lastBgColor);
if (lastCaret != null) editor.setCaret(lastCaret);
} else {
lastBgColor = editor.getBackground();
lastCaret = editor.getCaret();
editor.setBackground(disabledBgColor);
editor.setCaret(nullCaret);
}
}
示例2: loadArray
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public static Component loadArray(Object value) {
Component comp = null;
if (isViewableValue(value)) {
Object[] arr;
if (value instanceof Collection) {
arr = ((Collection<?>) value).toArray();
} else if (value instanceof Map) {
arr = ((Map<?,?>) value).entrySet().toArray();
} else if (value instanceof Object[]) {
arr = (Object[]) value;
} else {
int length = Array.getLength(value);
arr = new Object[length];
for (int i = 0; i < length; i++) {
arr[i] = Array.get(value, i);
}
}
JEditorPane arrayEditor = new JEditorPane();
arrayEditor.setContentType("text/html");
arrayEditor.setEditable(false);
Color evenRowColor = arrayEditor.getBackground();
int red = evenRowColor.getRed();
int green = evenRowColor.getGreen();
int blue = evenRowColor.getBlue();
String evenRowColorStr =
"rgb(" + red + "," + green + "," + blue + ")";
Color oddRowColor = new Color(
red < 20 ? red + 20 : red - 20,
green < 20 ? green + 20 : green - 20,
blue < 20 ? blue + 20 : blue - 20);
String oddRowColorStr =
"rgb(" + oddRowColor.getRed() + "," +
oddRowColor.getGreen() + "," +
oddRowColor.getBlue() + ")";
Color foreground = arrayEditor.getForeground();
String textColor = String.format("%06x",
foreground.getRGB() & 0xFFFFFF);
StringBuilder sb = new StringBuilder();
sb.append("<html><body text=#"+textColor+"><table width=\"100%\">");
for (int i = 0; i < arr.length; i++) {
if (i % 2 == 0) {
sb.append("<tr style=\"background-color: " +
evenRowColorStr + "\"><td><pre>" +
(arr[i] == null ?
arr[i] : htmlize(arr[i].toString())) +
"</pre></td></tr>");
} else {
sb.append("<tr style=\"background-color: " +
oddRowColorStr + "\"><td><pre>" +
(arr[i] == null ?
arr[i] : htmlize(arr[i].toString())) +
"</pre></td></tr>");
}
}
if (arr.length == 0) {
sb.append("<tr style=\"background-color: " +
evenRowColorStr + "\"><td></td></tr>");
}
sb.append("</table></body></html>");
arrayEditor.setText(sb.toString());
JScrollPane scrollp = new JScrollPane(arrayEditor);
comp = scrollp;
}
return comp;
}
示例3: loadArray
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public static Component loadArray(Object value) {
Component comp = null;
if (isViewableValue(value)) {
Object[] arr;
if (value instanceof Collection) {
arr = ((Collection<?>) value).toArray();
} else if (value instanceof Map) {
arr = ((Map<?,?>) value).entrySet().toArray();
} else if (value instanceof Object[]) {
arr = (Object[]) value;
} else {
int length = Array.getLength(value);
arr = new Object[length];
for (int i = 0; i < length; i++) {
arr[i] = Array.get(value, i);
}
}
JEditorPane arrayEditor = new JEditorPane();
arrayEditor.setContentType("text/html");
arrayEditor.setEditable(false);
Color evenRowColor = arrayEditor.getBackground();
int red = evenRowColor.getRed();
int green = evenRowColor.getGreen();
int blue = evenRowColor.getBlue();
String evenRowColorStr =
"rgb(" + red + "," + green + "," + blue + ")";
Color oddRowColor = new Color(
red < 20 ? red + 20 : red - 20,
green < 20 ? green + 20 : green - 20,
blue < 20 ? blue + 20 : blue - 20);
String oddRowColorStr =
"rgb(" + oddRowColor.getRed() + "," +
oddRowColor.getGreen() + "," +
oddRowColor.getBlue() + ")";
Color foreground = arrayEditor.getForeground();
String textColor = String.format("%06x",
foreground.getRGB() & 0xFFFFFF);
StringBuilder sb = new StringBuilder();
sb.append("<html><body text=#").append(textColor).append("><table width=\"100%\">");
for (int i = 0; i < arr.length; i++) {
if (i % 2 == 0) {
sb.append("<tr style=\"background-color: ")
.append(evenRowColorStr).append("\"><td><pre>")
.append(arr[i] == null ?
arr[i] : htmlize(arr[i].toString()))
.append("</pre></td></tr>");
} else {
sb.append("<tr style=\"background-color: ")
.append(oddRowColorStr).append("\"><td><pre>")
.append(arr[i] == null ?
arr[i] : htmlize(arr[i].toString()))
.append("</pre></td></tr>");
}
}
if (arr.length == 0) {
sb.append("<tr style=\"background-color: ")
.append(evenRowColorStr).append("\"><td></td></tr>");
}
sb.append("</table></body></html>");
arrayEditor.setText(sb.toString());
JScrollPane scrollp = new JScrollPane(arrayEditor);
comp = scrollp;
}
return comp;
}