• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java Applet Window

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

I have extended the JComboBox to create myown combobox.
But when I use it, in the combo drop down I can see "Java Applet Window" message.

Please inform me how to get rid of this if possible.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds odd. I think we'd need to see a minimal example of code that demonstrates this behavior.
 
Mahesh x Bogadi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see the below code.

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JComboBox;
import javax.swing.JTable;

public class FilterComboBox extends JComboBox
{
private longmin_val= 0;
private longmax_val= 0xffff;

public FilterComboBox(String[] types)
{
super(types);
setEditable(true);
getEditor().getEditorComponent().addKeyListener(new KeyListener()
{
public void keyTyped(KeyEvent arg0)
{
processKeyEvent(arg0);
}

public void keyPressed(KeyEvent arg0)
{
}

public void keyReleased(KeyEvent arg0)
{

}
});
}

/*----------------------------------------------------------------------------*/
/**
* Get Table Cell Renderer Component. Overridden so we can right justify
* this
*/

/*----------------------------------------------------------------------------*/
/**
* Get Min Value. Gets the minimum number this field can hold.
*
* @return the min value.
*/
/*----------------------------------------------------------------------------*/
public long getMinVal()
{
return min_val;
}

/*----------------------------------------------------------------------------*/
/**
* Get item. The overloaded get text function. Returns min_val if the number
* does not contain a valid number string.
*
* @return the number string in the field.
*/
/*----------------------------------------------------------------------------*/
public synchronized String getSelectedItem()
{
String ret = ((String) super.getSelectedItem()).toUpperCase();
//if (getSelectedIndex() >= 0)
{
return ret;
}

/*
long l = 0;
try
{
// Check the validity of the number
if (getSelectedIndex() < 0)
{
l = Long.valueOf((String) super.getSelectedItem(), 16);

if (l < min_val)
{
l = min_val;
}
else if (l > max_val)
{
l = max_val;
}
}
}
catch (NumberFormatException e)
{
// Number not valid, return minimum value
l = min_val;
}

// Number is valid
return Long.toHexString(l).toUpperCase();
*/
}

/*----------------------------------------------------------------------------*/
/**
* Process Key Event. The overloaded key event function. It is overloaded so
* we can limit the number of characters in the TextField
*
* @param evt
* The Key event
*/
/*----------------------------------------------------------------------------*/

public void processKeyEvent(KeyEvent evt)
{
// Only allow hex digits and 'special' keys
if (evt.getID() == KeyEvent.KEY_TYPED)
{
// Only process valid key inputs
if (isValidChar(evt.getKeyChar()))
{
if (((String) getEditor().getItem()).length() < 4 || isNonPrintableChar(evt.getKeyChar()))
{
super.processKeyEvent(evt);
return;
}
}

evt.consume();
}
else
{
super.processKeyEvent(evt);
}
}

/*----------------------------------------------------------------------------*/
/**
* Is Valid Char. Checks to see if the character is valid for this field.
*
* @param c
* the character.
* @return true if valid, false otherwise.
*/
/*----------------------------------------------------------------------------*/

private boolean isValidChar(char c)
{
switch (c)
{
// Allow normal processing for these keys
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case KeyEvent.VK_BACK_SPACE:
case KeyEvent.VK_TAB:
case KeyEvent.VK_ENTER:
case KeyEvent.VK_DELETE:
return true;

default:
return false;
}
}

/*----------------------------------------------------------------------------*/
/**
* Is Non Printable Character. We can process these chars even if we are
* full.
*/
/*----------------------------------------------------------------------------*/

private boolean isNonPrintableChar(char c)
{
switch (c)
{
case KeyEvent.VK_BACK_SPACE:
case KeyEvent.VK_TAB:
case KeyEvent.VK_ENTER:
case KeyEvent.VK_DELETE:
return true;

default:
return false;
}
}

/*----------------------------------------------------------------------------*/
/**
* Process Focus Event. Adjusts the value of the text field when focus
* leaves.
*
* @param evt
* The Focus event.
*/
/*----------------------------------------------------------------------------*/
/*
public void processFocusEvent(FocusEvent evt)
{
this.adjustUp();

super.processFocusEvent(evt);
}

/*----------------------------------------------------------------------------*/
/**
* Adjust Up. If the value in the text field is too small, adjust it to be
* the minimum value.
*/
/*----------------------------------------------------------------------------*/
public void adjustUp()
{
// if the field is blank, leave it
if (super.getSelectedIndex() >= 0)
return;

try
{
Long val = Long.valueOf((String) super.getSelectedItem(), 16);

// Set to min_val if we are currently under
if (val.longValue() < min_val)
{
this.setSelectedItem("");
}
else if (val.longValue() > max_val)
{
this.setSelectedItem("" + Long.toHexString(max_val));
}
}
catch (NumberFormatException e)
{
// Set to min_val if the value is not an integer.
this.setSelectedItem("");
}
}
}
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
Climb the rope! CLIMB THE ROPE! You too tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic