Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JComboBox;

import javax.swing.text.JTextComponent;

public class Main {
    /**
     * When the text is longer than the text box it gets centered, this
     * method ensures they all show the end of the text, eg the filename.
     */
    public static void setCaretPosition(JComboBox comboBox) {
        Object item = comboBox.getSelectedItem();
        if (item != null) {
            String val = item.toString();
            JTextComponent c = (JTextComponent) comboBox.getEditor().getEditorComponent();
            c.setCaretPosition(val.length());
        }
    }
}