I know a possible solution, unfortunately it is a bit long, but if it works for you, perfect.
To begin, you need a class that includes two values, the point is that you create a list with the word that starts, example: "Seawater" and its value "Water".
public class Tipo {
private String nombre, valor;
public Tipo(String nombre, String valor) {
this.nombre = nombre;
this.valor = valor;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getValor() {
return valor;
}
public void setValor(String valor) {
this.valor = valor;
}
@Override
public String toString() {
return nombre;
}
}
The important thing here is that the toString () method only shows the value you want to show inside the JComboBox, so you can create several objects I recommend using an ArrayList and enter it with a for the JcomboBox
public class Valor extends JFrame {
private JComboBox<Tipo> cbCaja; //Tiene que ser del mismo tipo que tu clase
private JButton btnBoton;//El botón es solo para crear un evento
private ArrayList<Tipo> lista; //La lista también debe ser del tipo de tu clase
public Valor() throws HeadlessException {
setSize(100, 200);
setDefaultCloseOperation(3);
setLocationRelativeTo(null);
setLayout(null);
//Aquí creo los objetos, pero en tu caso los puedes crear con Query
lista = new ArrayList<>();
lista.add(new Tipo("Agua de Mar", "Agua"));
lista.add(new Tipo("Sedimiento Marino", "Sedimiento"));
lista.add(new Tipo("Tejido Biologico", "Tejido"));
cbCaja = new JComboBox<>();
cbCaja.setBounds(10, 10, 100, 20);//Se agregan al combo
for (int i = 0; i < lista.size(); i++) {
cbCaja.addItem(lista.get(i));
}
btnBoton = new JButton("Boton");
btnBoton.setBounds(10, 100, 80, 20);
btnBoton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//En el evento obtengo el objeto seleccionado
Tipo seleccionado = (Tipo) cbCaja.getSelectedItem();
//Para llamar el valor solo invocas el metodo .getValor()
JOptionPane.showMessageDialog(null, ""
+ "El nombre: " + seleccionado.getNombre() + "\n"
+ "El valor: " + seleccionado.getValor());
}
});
add(btnBoton);
add(cbCaja);
setVisible(true);
}
public static void main(String[] args) {
Valor v = new Valor();
}
}
I know it's a bit extensive, but it's functional.
Greetings