Question: How do we change the textSize based on Resolution density? 

I have found several ways on SO, but all of them usng java code to do that.

I however need a java free approach because I have someplaces where I set a textSize on XML and some on Java code.

In xml, I do this

```
        android:textSize="@dimen/FONT_SIZE_SMALL"

```

however sometimes I need to set it via java code.

```
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.FONT_SIZE_SMALL);

```

Any ideas please? is it doable?

Answer: 
An enum is a collection of static instances of that enum type. Therefore `ColumNames.FIRSTNAME` is of type `ColumNames`, while you need a String for header. You can either use the the value of the instance, however this might not give you what you want:

```
public enum ColumNames {
    FIRSTNAME, LASTNAME, DEPARTMENT, SALARY,
    YEARS, VEGETARIAN, GENDER,AGE;
}
final int numberOfColumns = ColumNames.values().length;
columnNames = new String[numberOfColumns ];
for (int i = 0; < numberOfColumns; i++) {
  columnNames[i] = ColumNames.values()[i].name();
}

```

This will give you the equivalent array to:

```
columnNames = new String[] { "FIRSTNAME", "LASTNAME", "DEPARTMENT", "SALARY", "YEARS", "VEGETARIAN", "GENDER", "AGE" };

```

Or you can define a display method on your `enum` and use that instead of `name()`:

```
public enum ColumNames {
    FIRSTNAME("FirstName"), 
    LASTNAME("LastName"),
    DEPARTMENT("Department"),
    SALARY("Salary",
    YEARS("Years"),
    VEGETARIAN("Vegetarian"), 
    GENDER("Gender"),
    AGE("Age");
    private final displayName;
    private ColumNames(String displayName){
      this.displayName = displayName;
    }
    public String getDisplayName() {
      return displayName;
    }
}

```

However if internationalization is an issue, the first approach is the better one, as it uses a constant string independent of the local an can be replaced in the user interface.
You need to use an action listener, otherwise the application would not be aware if an action has been performed, here is an example of the method setUpSalColumn:

```
private void setUpSalColumn(JTable table, TableColumn column) {
        TableColumn salary = table.getColumnModel().getColumn(3);
        textBox.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e) {
                validateSal();
            }

            public void removeUpdate(DocumentEvent e) {
                validateSal();
            }

            public void insertUpdate(DocumentEvent e) {
                validateSal();
            }

            public void validateSal() {
                Pattern pattern = Pattern.compile("^[0-9]*$");
                String s = textBox.getText();
                Matcher m = pattern.matcher(s);
                if ((!m.matches())) {
                    JOptionPane.showMessageDialog(null, "enter numbers only");
                } else {
                    textBox.setEditable(true);
                }
            }
        });
        salary.setCellEditor(new DefaultCellEditor(textBox));

    }

```