Example usage for javax.swing JList requestFocus

List of usage examples for javax.swing JList requestFocus

Introduction

In this page you can find the example usage for javax.swing JList requestFocus.

Prototype

public void requestFocus() 

Source Link

Document

Requests that this Component gets the input focus.

Usage

From source file:kenh.xscript.elements.Debug.java

private void list(JList c) {
    if (result == null)
        return;// w w  w  .j  ava2  s  .  c om

    if (StringUtils.isBlank(c.getSelectedValue().toString()))
        return;

    if (this.getEnvironment() != null) {

        String context = "";
        try {
            Object obj = this.getEnvironment().getVariable(c.getSelectedValue().toString());
            if (obj != null) {

                context = c.getSelectedValue().toString() + LINE_SEP + LINE_SEP;

                context += "-- Class: " + obj.getClass().getCanonicalName() + LINE_SEP;

                context += LINE_SEP;
                context += "-- Fields: " + LINE_SEP;
                Field[] fields = obj.getClass().getFields();

                for (Field field : fields) {
                    int i = field.getModifiers();
                    String retval = Modifier.toString(i);
                    if (StringUtils.contains(retval, "public")) {
                        context += "\t" + field.getName() + " - " + retval + LINE_SEP;
                    }
                }

                context += LINE_SEP;
                context += "-- Method: " + LINE_SEP;
                java.lang.reflect.Method[] methods = obj.getClass().getMethods();

                for (java.lang.reflect.Method method : methods) {
                    int i = method.getModifiers();
                    String retval = Modifier.toString(i);
                    if (StringUtils.contains(retval, "public")) {
                        Class[] pcs = method.getParameterTypes();
                        StringBuffer sb = new StringBuffer();

                        for (Class c_ : pcs) {
                            String s = c_.getSimpleName();
                            sb.append(s + ", ");
                        }

                        String p = StringUtils.trimToEmpty(StringUtils.substringBeforeLast(sb.toString(), ","));

                        context += "\t" + method.getName() + "(" + p + ") - " + retval + LINE_SEP;
                    }
                }

            } else {
                context = "<null>";
            }
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            context = sw.toString();
        }

        result.setText(context);

    } else {
        result.setText(c.getSelectedValue().toString());
    }

    result.setCaretPosition(0);
    c.requestFocus();
}