aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Java Applet Window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Applet Window" Watch "Java Applet Window" New topic
Author

Java Applet Window

Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
This sounds odd. I think we'd need to see a minimal example of code that demonstrates this behavior.


Ping & DNS - my free Android networking tools app
Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
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("");
}
}
}
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to Swing/AWT...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Applet Window