Editable ComboBox in JOptionPane
Can we have an editable comboBox in JOptionPane. Everything matches my requirements in the JOptionPane except that the comboBox is non editable. Can I make it editable instead of writting my own class which does this purpose...
??
Actually found something similar which resolves the issue..
Following is the code snippet......
final JPanel panel = new JPanel();
String[] choices = new String[] {"choice1", "choice2"};
final JComboBox combo = new JComboBox(choices);
combo.setEditable(true);
panel.add(combo);
if (JOptionPane.showConfirmDialog (null, panel,"Save As", JOptionPane.OK_CANCEL_OPTION) ==JOptionPane.OK_OPTION) {
System.out.println("Saving " + combo.getSelectedItem());
Similar Messages
-
Set border color of editable ComboBox on focus
What I want to do, is set BorderBrush of editable ComboBox. I'm using slightly modified default WPF templates. They are structured like below:
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
<Grid x:Name="templateRoot" ...>
<ToggleButton x:Name="toggleButton" ... />
<Border x:Name="border" ...>
<TextBox x:Name="PART_EditableTextBox" ... />
<!-- textbox with IsFocused property which should be focus trigger -->
</Border>
</Grid>
</ControlTemplate>
ToggleButton template:
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="templateRoot" ...> <!-- first border brush I want to set on focus -->
<Border x:Name="innerBorder" ...> <!-- second border brush I want to set on focus -->
<Border x:Name="splitBorder" ...>
<Path x:Name="arrow" ... />
</Border>
</Border>
</Border>
</ControlTemplate>
And now, what should happen.
When PART_EditableTextBox.IsFocused is equal to true then set
templateRoot.BorderBrush and innerBorder.BorderBrush to another color (for example red and blue).
It would be very simple if there was only one BorderBrush to set, because I could use
TemplateBinding to bind this property to ToggleButton element.
For me, the problem are nested templates. I don't know how to refer to inside of another template.
I hope you can help me.
It would be very good if I didn't need to use C# code, just XAML.>>I don't know how to refer to inside of another template.
You cannot. But since the PART_EditableTextBox is part of the ControlTemplate of the ComboBox you could add the trigger to this control template and then for example set the BorderBrush property and the Background propery of the ToggleButton and bind these
to the BorderBrush properties of the Borders in its ControlTemplate:
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
<TextBox x:Name="PART_EditableTextBox" ... />
<ToggleButton x:Name="toggleButton" ... />
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True" SourceName="PART_EditableTextBox">
<Setter Property="BorderBrush" TargetName="toggleButton" Value="Red"/>
<Setter Property="Background" TargetName="toggleButton" Value="Blue" />
</Trigger>
</ControlTemplate.Triggers>
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="2">
<Border x:Name="innerBorder" BorderBrush="{TemplateBinding Background}" BorderThickness="2">
<Border x:Name="splitBorder">
<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}"
Fill="Black" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/>
</Border>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If you don't want to use the Background property for this, the other option is to create your own custom class that derives from the ToggleButton class and add a dependency property called "InnerBackground" or something to this class and replace
the ToggleButton with your custom ToggleButton and replace the binding to the Background property with a binding to the new dependency property and set this one in the control template for the ComboBox.
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and/or helpful and please start a new thread if you have a new question. -
1. addKeyListener(..) not working onto editable combobox.
2. how to scroll the editable combobox when user types into it?
(in case of solving 1st problem, this one is solved too). Maybe there are special methods??
Thank you very much.
Boris.1) you need to add the listener to the editor of the combobox, no the combobox itself.
2) scroll? I thought it already does an auto select if there is a value in the list which starts with what's typed. -
Hi All,
I have a editable combobox in a normal JTable as one of columns.Can any body help me to set the size to the entered text in editable combobox. Means if I set the length to 5 then it should accpet only 5 characters.so how to achive it ??
Regards
SureshFirst get cell editor that should be a combobox. Then get its editor that should be text box and then set its size.
-
Losing focus on editable combobox
Hi everyone!
I have created a combobox and setEditable is set to true but it does not react to the focus lost method.But when the setEditable is set to false then the focus lost method is executed. According to the following Sun Developer sites(http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6433257,
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4628933) this is some kind of bug.
Is there no way that I can have an editable combobox that reacts to the focus lost method I mean that loses focus?When you have an editable combo box the editor has focus, not the combox box. So I guess you would need to add the FocusListener to the editor itself and not the combo box directly.
-
Hi
is it possible to make the combobox editable ?
pls adviceHI Sireesha Pinninti ,
yaa , Normal combobox is not editable
is there any alternative for Editable combobox similar to InputComboBoxListofValues
my requirement is if i have a Country combo box with 2 option India and US , if the enmd user want to opt China , he could type tht
pls advice
Regards
Jeethi George -
Changing the font of a non-editable ComboBox
Hello everyone,
I need a small combobox. So I set a font of a specific size to the combo's
editor. That works nice als long as the combo is editable; but when it becomes
uneditable, the default bold font is used and some items don't fit in the
field any more. How to prevent this?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
class ComboEditorFont extends JFrame {
Font fontM= new Font("Monospaced", Font.PLAIN, 13);
public ComboEditorFont() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(100,100);
setLayout(null);
// Changing the font in the UIManager doesn't work either
/* Font defaultComboBoxFont= UIManager.getFont("ComboBox.font");
FontUIResource fui= new FontUIResource(fontM);
UIManager.put("ComboBox.font", fontM);
// UIManager.put("ComboBox.font", fui);
JComboBox cmb = new JComboBox(new String[]{"ABC","DEF","GHI","LMO"});
cmb.setBounds(20,20, 48,20);
// cmb.setEditable(true);
JTextField editor= (JTextField)(cmb.getEditor().getEditorComponent());
editor.setFont(fontM);
// cmb.setRenderer(new MyCellRenderer());
add(cmb);
// UIManager.put("ComboBox.font", defaultComboBoxFont);
setVisible(true);
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new ComboEditorFont();
class MyCellRenderer extends JLabel implements ListCellRenderer {
public MyCellRenderer() {
setOpaque(true);
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
setFont(fontM);
setText(value.toString());
Color background;
Color foreground;
JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation!=null && !dropLocation.isInsert() &&
dropLocation.getIndex() == index) {
background = Color.BLUE;
foreground = Color.WHITE;
} else if (isSelected) {
background = list.getSelectionBackground();
foreground = list.getSelectionForeground();
} else {
background = list.getBackground();
foreground = list.getForeground();
setBackground(background);
setForeground(foreground);
return this;
}- an offense to the english grammarThe exaggeration was meant to be ironic, not mean. Seriously, if a post is unreadable why bother posting it at all?
offense/non offense, I'd start to teach this language on 15/oct/2009, untill now ---> MSDN, ASM,I don't know if you refer to the Java or English language...
Either way, hopefully you have merely started learning it - not teaching it! :o)
- ranging from slightly to completely off-topic
always exists the different way, my off-topic "for you hide" declaracion for topic,
I agreed with some rules, disagre with strict..., Swing = something based on variable interpretations about Java decl., isn't exist stricts borders there, only God can tell us, If is it Swing, or if isn't Swing relevants, not my trully,No, no, I meant "off-topic" with regard to the poster's question: he had tackled the problem for editable comboboxes already, and was specifically talking about non-editable comboboxes, so obviously altering the editor as you suggested was hopeless.
- giving out "coding advice" without any justification
be sure that 99pct from "answers" fired these guys find out the "coding advice" on Go..., on another forum(s), and they will not returns back here anymore, for not-acceptable Hot Potato Games (if is or isn't topic relevant for this forum), I'm afraid the grammar prevented me to understand this whole sentence...
help is by Camickr's company, by German Kommunität (rel. for EU TimeZone), I'm only to learn (somehow) this language, Read - Translate ---> T - Write, An online translation system may help you to read these forums, but really don't post text translated this way!
with peaceFullFace and takeAnyNoticeOfIt kopik,No personal offense meant, I now think you're well-intended (but really awkward all the same).
Edited by: jduprez on Nov 6, 2009 4:06 PM - fixed spelling - mind you, I'm not a native english speaker either! -
How to exit edit mode (editable comboBox)?
I have an editable comboBox. When a user clicks on the text
area, he can rename the text and the idea is to click outside the
comboBox to commit the new value.
The problem now is when the user clicks outside the comboBox,
the comboBox remains in edit mode(with the blinking prompt). How do
I make it get out of that mode?
thanks in advanceHi,
setting comBox.editable=false in the function where you
commit the vaules will solve this purpose.
Also remember to set it in edit mode when click event on the
combobox happens
Ex.
<mx:ComboBox id="comBox" click="setMode()"/>
public function setMode():void{
comBox.editable=true;
I hope I have given you a direction to think upon.
Take care -
I have created a application using combobox wherein the
combobox loads the names of the persons from an XML file. I have
created the application using XMLConnector component without
writing a single line of ActionScript code.
The editable property of the combobox is set to true. I would
like the combobox to display the person's names when the user types
the name directly in the editable combobox.
For Example: The combobox contains names like Alfred, John,
Sandy etc
If user types 'J' or 'Jo' the combobox shoud open up and
select the names starting with J.Use s:DropDownList instead.
Peter -
Hello All,
Did any body implement the jquery editable combobox? like the combobox in
http://stuff.rajchel.pl/jec/demos/#demo-1
Can you please tell me how to implement this?
that will be a great helpWanna post it and share with EVERYONE else??
That's the way this works here, sharing and HELPING everyone as a GROUP!
Thank you,
Tony Miller
Webster, TX -
Supporting maxChars on editable ComboBox, string validator null out input once max is reached
I have a ComboBox in a form set to editable, so it acts like a text input but as drop down values as well.
The data here is required and I want to limit the number of characters that can be entered, normally under a TextInput control you would just set the maxChars.
I have created a string validator, required is based on seletedLabel so that working as I would expect.
I set a maximum character limit in the validator which does not limit the text but prevents validation if the count is over, so far so good.
Now the issue, imagine you set this to 10 characters maximum, type the 11th character the validator correctly invalidates the control and the standard message pops up and prevent form submission.
But if the user is still typing as soon as you enter one character over the limit in this example the 12th character the input nulls out to empty string.
I want to limit the the number of characters that can be typed or the validator to not null out, giving the user a chance to back space instead of clearing the input.
Any ideas?
TIA
flash.I am probably missing something with all the scrolling up and down and back and forth, but I can't see how that line can throw an NPE. Or the constructor which it calls.
What is the exact runtime message? -
Editable ComboBox focus problem
Hi,
I have created a ComboBox with editable property set to true.
The problem is ... when the focus is on the ComboBox.... if I click somewhere outside, the focus still remains in the ComboBox.
Only tabbing out or shifting the focus to some other component, removes the focus from ComboBox.
Any help is appreciated.
Thanks in advance !!That should be true for any Flex component. Focus is always on something, you have to move it to a new place otherwise it gets restored back to what last had foucs.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui -
How to make non-editable ComboBox in flex.
Hi All,
I defined ComboBox as below and I'd like to make this combobox to non-editable(readonly)
<mx:ArrayCollection id="bb_list">
<mx:Object data="" label="-Please Select-"/>
<mx:Object data="Y" label="Yes"/>
<mx:Object data="N" label="No"/>
<mx:Object data="D" label="I Don't Know"/>
</mx:ArrayCollection>
<mx:ComboBox width="152" id="broad" dataProvider="{bb_list}" change="bb_service()" editable="false" > </mx:ComboBox>
Still it is displaying ComboBox where user can change value from this ComboBox, can anyone let me know how to make this ComboBox to non-editable.
Thanks in advance.
Regards,
Sharath.I really don't understand what you're trying to do.
In the ComboBox default state, you cannot type text into the non-drop-down portion. If you set it to editable, then you can type text in the non-drop-down portion.
But, in both of these situations, the user can still open the drop down and select a new value.
Do you want to display a drop down, but not give the users the ability to select a new option? If so, you might not be able to work something up by listening to the change event, although I would expect that to be non-conducive to good interface design.
If you don't want to show the drop down at all, use a Text component instead of a ComboBox.
You might also try disabling the ComboBox in order to prevent the user from interacting with it.
If you can elaborate on what behavior you're expecting and why it is unexpected, that might help us point you in the right direction. -
Graphical skin for editable ComboBox
I am using graphical skins to style a ComboBox. They work fine for a normal combobox. When I make it editable, Flex no longer uses the upSkin, overSkin and downSkin for the editable text area. It seems to use the default Flex skin instead. It is using my editableUpSkin, editableOverSkin and editableDownSkin for the arrow area, though. What do I need to change to use my graphical skins for both the editable text area and the arrow area?
Thanks!Maybe you need to specify a custom itemRenderer you have skinned as well.
If this post answers your question or helps, please mark it as such.
Greg Lafrance - Flex 2 and 3 ACE certified
www.ChikaraDev.com
Flex / AIR Development, Training, and Support Services -
OK, java jocks - I need help... I am a vb programmer (don't hold that against me) but need to do some java
stuff... I have included the following 'object' code but need to get it to do what a lot of you good folks have
already dealt with back in 2001... And that is, as the user starts typing in a codelist choice, the focus
moves to that item in the combobox... I tried to read through the various code classes offered up in this forum but can not get any to work for me... Any suggestions and remember I am a java beginner...
thanks, msp@duke
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EditableComboBox extends JDialog
implements ActionListener {
JFrame frame;
JLabel result;
String currentPattern;
public EditableComboBox() {
System.out.println("inside EditableComboBox constructor...");
JFrame frame = new JFrame("EditableComboBox");
//JPanel panel = new JPanel();
JPanel panel = new JPanel(new GridLayout(5,1));
//panel.setLayout(new GridLayout(5,1));
final JLabel label = new JLabel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] codelist = {
"1 - Code#1",
"2 - Code#2",
"3 - Code#3",
"4 - Code#4",
"5 - Code#5",
"6 - Code#6",
"7 - Code#7",
"8 - Code#8",
"9 - Code#9",
"10 - Code#10"
//currentPattern = codelist[0];
currentPattern = "";
//Set up the UI for selecting a pattern.
JLabel cboLabel1 = new JLabel("Enter the pattern string");
JLabel cboLabel2 = new JLabel("select one from the list:");
panel.add(cboLabel1);
panel.add(cboLabel2);
//Creates a JComboBox that contains the elements
// in the specified Vector
JComboBox cboList = new JComboBox(codelist);
cboList.setEditable(true);
cboList.addActionListener(this);
panel.add(cboList);
//Create the UI for displaying result.
JLabel resultLabel = new JLabel("You Selected:",JLabel.LEADING);
// add label
panel.add(resultLabel);
result = new JLabel("");
result.setForeground(Color.black);
result.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.black),
BorderFactory.createEmptyBorder(5,5,5,5)
panel.add(result);
frame.getContentPane().add(BorderLayout.CENTER,panel);
System.out.println("bottom of EditableComboBox constructor...");
frame.pack();
//frame.setSize(h,v);
frame.setSize(200,175);
frame.setVisible(true);
} //constructor
public void actionPerformed(ActionEvent e) {
System.out.println("inside actionPerformed...");
JComboBox cb = (JComboBox)e.getSource();
String newSelection = (String)cb.getSelectedItem();
currentPattern = newSelection;
validate();
/** Formats and displays today's date. */
public void validate() {
result.setText(currentPattern);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
System.out.println("inside main...");
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
EditableComboBox ec = new EditableComboBox();You need to write a KeyListener, which upon receiving
a keyEvent will do the following:
1) Get the current string from the ComboBox (or you
can internally keep track of it in a Char[]).
2) Loop through all the elements of the ComboBox to
check for a possible match
using startsWith() method (java.lang.String).
3) If match found, then use SetSelectedItem() on that
ComboBox to show the corresponding value.
But make sure you highlight only the portions of the
text to the right of cursor. (the one that will "most
likely" follow). Use setSelectionStart() and
SetSelectionEnd() to accomplish this.
+= KRRThx for the 3 step leads, KRR... I will try implementing them today...
cheers, msp@duke
Maybe you are looking for
-
Error while creating an HFM application
Hi, i am getting this error while creating an application in the HFM thick client and the workspace. error while creating an application in the Think client HFM. Error Reference Number: {20448166-D5EE-45B9-ABEB-13448BE7D956} Num: 0x80040225;Type: 1;D
-
I have an apple computer.A week or so ago a window appeared that ask if I wanted an upgrade on Mozilla Firefox & if so click on "Install" which I did. Somehow by mistake this changed my Firefox program from the English language to a foreign language.
-
Error Using LISTAGG SQL Function
Hello, I'm trying to use the new LISTAGG SQL function with the following expression in a report: select listagg(email, ';') within group (order by email) as email_list from sba_registration_entries where team=241 and I get the following SQL error in
-
Getting Error in Demantra BM Build Model procedure
Hello, I am getting following Error in Demantra BM Build Model procedure "ORA-00907: missing right parenthesis problem with procedure :time_buck"
-
1- Is there any available tools that can help in publishing Discoverer workbooks that enable end user easily decorate reports. 2- Is there any plans to support Arabic langauage in near future. can we promise customers?