JTable & JComboBox - huge empty dropdown
I was wondering if anyone experienced this.
In my application, which has a JComboBox as CellEditor in a JTable, it rarely happens that when the dropdown list opens, it is huge (as tall as the screen or so) and it contains a few or no items.
Since this is a network application, the problem might be malformed data, but to avoid long and boring reverse engineering, I ask you if you ever experienced this before starting to work on the protocol.
Thanks in advance
I was wondering if anyone experienced this.
In my application, which has a JComboBox as CellEditor in a JTable, it rarely happens that when the dropdown list opens, it is huge (as tall as the screen or so) and it contains a few or no items.
Since this is a network application, the problem might be malformed data, but to avoid long and boring reverse engineering, I ask you if you ever experienced this before starting to work on the protocol.
Thanks in advance
Similar Messages
-
Empty dropdown in the inputComboboxListOfValues
Hi! There's some strange problem I'm stuck with. I have several inputComboboxLOVs on my page. They all work fine except one. When I press the dropdown button it shows only the "Search..." link and no items. When I click "search" I see all the expected data in the opened dialog. And after that (empty dropdown -> click on the "Search" -> select some item) this LOV begins to work just fine. Where can be the problem? I'v got another LOV (and it is quite similar: they both update 2 fields, their VOs both have bind variables in their criterias) next to it and it works fine from the beginning.
Hi Venku,
Take any Key Figure->Properties
Calculate Single Value As->Suppress Result
Calculate Result As->Suppress Result -
Empty Dropdown after adding variable reference to
Hi ,
I am facing a problem while trying to convert the currency from the report result.After right click and select Gloal currency translation ,it is giving me an empty dropdown menu.
If I give a fixed date in the currency translation type in T- code RSCUR ,it works fine ,I get all the translation type I created in the dropdown menu.When I give a variable for time reference
dropdown menu is empty.have anyone faced this earlier?
we are on BI platform
Thx
sheebaHi,
First step is the check the data insde P table ( example /BIC/PXXX which will be there in the in master data and text tab)
if you find the data for newely added attributes then it works fine.
or else
Delete the master data
programs for individual IinfoObject master data deletion:
RSDMD_DEL_BACKGROUND or RSDMD_DEL_MASTER_DATA_TEXTS
then delete the transformation and recreate the transformation followed by DTP once again
activate all atributes individually once again
load data to the infoobject and check it.
you should be able to relove the problem
santosh -
UWL Configuration Wizard - Empty Dropdown
Hi All,
System Info : EP7 SP18.
UWL Navigation Node Configuration Wizard shows empty dropdown, under the property " Select the Navigation Node To Be Customized. In the UWL documentation , it shows one dropdown as MAIN,however in this case there are no dropdown and as such the below table is not available.
How can I resolve this?
Any help would be appreciated.
Kind Regards,
Vikram SaxenaThe work around mentioned in the 'link' provided by Kumar does not work.
SAP has not responded to our OSS Note regarding the UWL Conf wizard not working.
Anyone else know how to get the wizard to work in NW 7.0. We are on SP 20.
Thanks,
D. Maupin
University of Kentucky -
How do I create a JTable with some empty cells in it?
I have a three column JTable. The first column is a String showing description. The second column contains numbers (double) and the third column also contains numbers. In some cases not all cells in a row should contain data. So for instance, I could have row one showing only description (a String in the first column), and then row two showing description (a String in the first column) and a number (a double in the second column) in columns one and two respectively. My problem is that, the data gets copied from the cells with data to the cells which are supposed to be empty. So, how do I create a JTable with some empty cells in it.
I have tried empty strings for those values, but it did not work. My table puts objects in an arraylist called reconciliation. The arraylist takes different objects with the same super class. The code below explains. Are you suggesting I pass null to my constructor?
JTable table = new JTable(new ReconTableModel());The method below is from the table model
protected List<Reconciliation> reconciliation = new ArrayList<Reconciliation>();
protected void fillModel(){
reconciliation.add(new CashBook("Cash Book Report"," "," "));
reconciliation.add(new CheckingBankAccount("Checking Bank Account"," "," "));
reconciliation.add(new BankBalance("Bank Balance As Per Bank Statement",500," "));
reconciliation.add(new PaymentVouchers("Payment Voucher Receipt",300," "));
reconciliation.add(new DepositVoucher("Deposit Voucher Receipt",1000," "));
reconciliation.add(new ReconciledBalance("Reconcilied Bank Balance",1200," "));
reconciliation.add(new BalanceAt("Bank Balance At",800," "));
reconciliation.add(new Difference("Difference",400," "));
Collections.sort( reconciliation, new Comparator<Reconciliation>(){
public int compare( Reconciliation a, Reconciliation b) {
return a.getTransactionName().compareTo( b.getTransactionName());
} -
JTable JComboBox display Problems
I have a JTable which uses JCombobox's to display one column's infomation.
Most times this works perfectly well and displayes correctly.
But sometimes the combo box will not be displayed at all in the table (just get a white cell). When clicked apon the combo box works correctly and the information is in the cell, as it is used latter on in the program . Once a value is selected in the combo box the cell goes back to being white.
The only corrilation I can find is that this seems to occure more frequently when I am debugging or running alot of programss in the back ground.
Any suggestiongs on where I can start looking.
ThanksSounds like the Cell Renderer is not working as expected.
- that might be a starting point for you, hard to say much more without
any code... -
Huge Empty Space at Bottom of WebPage
Hi:
I've been trying to build a template for eBay auctions. I've
been able to create what I want--except for the fact that there is
a huge space at the bottom of my design. It's noticeable in Firefox
and Safari, but the space is enormous in IE. In fact, IE nearly
doubles the length of the webpage with worthless space! I will
include a link to the template that I am working on. How can I get
rid of this empty space at the end?
Link:
http://www.lucid-dreams.com/ebay/eBay.html
Thank you for any help!I got a little carried away, but try this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#Container {
width: 800px;
margin-right: auto;
margin-left: auto;
border-top-style: double;
border-right-style: double;
border-bottom-style: double;
border-left-style: double;
overflow:hidden;
#Header {
height: 87px;
width: 800px;
border-bottom-style: double;
#LeftBox {
float: left;
width: 212px;
background-color: #ccc;
font-size: 24px;
text-align: center;
padding-right: 5px;
padding-left: 5px;
#MainText {
float: left;
width: 575px;
background-color: #FFF;
#Body {
width: 800px;
background-color: #CCC;
overflow:hidden;
#Return-Policy {
background-color: #FFF;
width: 800px;
margin-right: auto;
margin-left: auto;
text-align: center;
#Title {
float: left;
width: 575px;
background-color: #FFF;
font-size: 24px;
color: #00F;
text-align: center;
#Shipping {
background-color: #FFF;
width: 575px;
float: left;
-->
</style>
</head>
<body>
<div id="Container">
<div id="Header">
<p>Logo will go Here</p>
</div>
<div id="Body">
<div id="LeftBox">
<p>New! </p>
<p>Factory Sealed! </p>
<p>Free Shipping!</p>
<p>Ships Same Day or Next Day! </p>
<p>We e-mail Tracking Numbers! </p>
<p>100% Positive Feedback! </p>
</div>
<div id="Title">
<p><span id="Font24">Title of
Auction</span><br />
and maybe a subtitle
</p>
</div>
<div id="MainText">
<p>This Div is where the product will be described in
detail. </p>
<p>This Div will vary in size from Auction to
Auction.</p>
</div>
<div id="Shipping">
<table width="575" border="1" summary="Accepted Payment
Methods and
Shipping Rates">
<caption>
</caption>
<tr>
<th colspan="2" scope="col"><u><font
color="#0000FF"
size="4">Payment</font></u></th>
<th width="6" rowspan="6" scope="col"
bgcolor="#C0C0C0">
</th>
<th colspan="2" scope="col"><font color="#0000FF"
size="4"><u>Shipping</u></font></th>
</tr>
<tr>
<th width="80" scope="row">PayPal</th>
<td width="150"><p>Accepted; immediate shipment.
</p>
<p><strong>We will only ship to Confirmed
addresses.</strong></p></td>
<td width="81"><b>Within Continental United
States:</b></td>
<td width="128">Free</td>
</tr>
<tr>
<th scope="row">Cashier's Check</th>
<td>Ships 7 days after received</td>
<td><b>Outside Continental United
Stated:</b></td>
<td>Please contact for price
<em>before</em> bidding or
buying.</td>
</tr>
<tr>
<th scope="row">Money Order</th>
<td>Ships 7 days after received</td>
<td colspan="2"><b><font
color="#008000"><center>We ship
<em>Fast!</em></center></font></b></td>
</tr>
<tr>
<th scope="row">Personal Check</th>
<td>Ships 7 days after received</td>
<td colspan="2"><font
color="#ff0000">Tracking</font>
included! We will email to you
the tracking number soon after I send the
package.</td>
</tr>
<tr>
<th scope="row">Cash</th>
<td>Unacceptable</td>
<td colspan="2">All Checks Payable to</td>
</tr>
</table>
</div>
</div>
</div>
<div id="Return-Policy">
<p><strong>Return
Policy</strong></p>
<ul>
<li>30 Day Satisfaction Guarantee </li>
<li>All unopened items shipped within the last 30 days
may be sent
back to us for a full refund.</li>
<li>Return shipping charges will not be
reimbursed.</li>
<li>Refund will be issued by the original method of
payment.</li>
<li> No exchanges or store credits will be
given.</li>
<li>Refunds will only be issued for items
returned</li>
</ul>
</div>
</body>
</html>
<!-- text below generated by server. PLEASE REMOVE
--><!--
Counter/Statistics data collection code --><script
language="JavaScript"
src="
http://us.js2.yimg.com/us.js.yimg.com/lib/smb/js/hosting/cp/js_source/whv2_001.js"></scrip t><script
language="javascript">geovisit();</script><noscript><img
src="
http://visit.webhosting.yahoo.com/visit.gif?us1236447682"
alt="setstats" border="0" width="1"
height="1"></noscript>
"Lucid Dreams" <[email protected]> wrote in
message
news:[email protected]...
> Hi:
>
> I've been trying to build a template for eBay auctions.
I've been able to
> create what I want--except for the fact that there is a
huge space at the
> bottom of my design. It's noticeable in Firefox and
Safari, but the space
> is
> enormous in IE. In fact, IE nearly doubles the length of
the webpage with
> worthless space! I will include a link to the template
that I am working
> on.
> How can I get rid of this empty space at the end?
>
> Link:
http://www.lucid-dreams.com/ebay/eBay.html
>
> Thank you for any help!
>
> -
JTable JComboBox setEditable(true) does what?
The JTable column uses JComboBox. What is expected of combo.setEditable(true)? Here is the relevant code.
Thanks
for (int k = 0; k < m_data.getColumnCount (); k++)
TableCellRenderer renderer = null;
TableCellEditor editor = null;
if (k==0) /* sysname column */
renderer=new DefaultTableCellRenderer();
JComboBox combo= new JComboBox(sys_names);
combo.setRequestFocusEnabled(false);
combo.setBackground(Color.yellow);
combo.setEditable(true);
combo.getEditor().getEditorComponent().setBackground(Color.blue)
editor=new DefaultCellEditor(combo);
[\code]That fits my limited experience. I'm currently only providing non-editable combos as the focus handling and traversal gets messy with editable ones. This may be due tosome other code I've put in to alter the default JTable behaviour, but I havn't had time to look into it yet.
-
Jtable+JComboBox=?
Hi!
I want to implement a component that should be:
It should look like a JComboBox but it's visible string must be divided into columns like a jtable row. When a user clicks right arrow (like in combobox), a scrollable JTable pops up (like combo box popup) and user now can pick another row. Is it possible to implement this? How?
Thanks.See the demo pasted below. It displays a table in combobox popup. It has only a column but you can customize it using table model to have more then one row.
Now you should use a custom renderer to display currently selected item. You can use JTable for it.
import java.awt.*;
import javax.swing.*;
public class TablePopupComboFrame extends JFrame {
JPanel jPanel1 = new JPanel();
JComboBox combo = new JComboBox();
String items [] = {"pratap","singh"};
JComboBox jComboBox1 = new JComboBox(items);
public TablePopupComboFrame() {
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
combo.addItem("one");
combo.addItem("two");
combo.addItem("three");
combo.addItem("four");
combo.addItem("1");
combo.addItem("2");
combo.addItem("3");
combo.addItem("4");
combo.addItem("5");
combo.addItem("6");
combo.addItem("7");
combo.addItem("8");
combo.setUI(new MyComboUI());
combo.setBackground(Color.white);
public static void main(String[] args) {
TablePopupComboFrame f = new TablePopupComboFrame();
f.pack();
f.setLocation(300,300);
f.show();
private void jbInit() throws Exception {
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jComboBox1, null);
jPanel1.add(combo, null);
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.*;
import javax.swing.table.*;
public class TableComboPopup extends BasicComboPopup implements ListSelectionListener, ItemListener
private JList list = new JList();
private JComboBox combo;
private MyComboUI ui;
private PopupTableModel tm ;
private final JTable table;
private JScrollPane pane;
public TableComboPopup(JComboBox combo, MyComboUI ui)
super(combo);
this.combo = combo;
this.ui = ui;
tm = new PopupTableModel();
table = new JTable(tm);
table.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
public void mouseMoved(MouseEvent e) {
int row = table.rowAtPoint(e.getPoint());
if (row == -1)
return;
table.getSelectionModel().removeListSelectionListener(TableComboPopup.this);
table.getSelectionModel().setSelectionInterval(row,row);
table.getSelectionModel().addListSelectionListener(TableComboPopup.this);
pane = new JScrollPane(table);
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(this);
combo.addItemListener(this);
public void show()
System.out.println("show called ");
super.removeAll();
// tm.fireTableStructureChanged();
Dimension dim = new Dimension(combo.getPreferredSize().width,ui.getList().getPreferredScrollableViewportSize().height);
pane.setPreferredSize(dim);
pane.setBorder(ui.getList().getBorder());
super.add(pane);
table.getSelectionModel().removeListSelectionListener(this);
selectRow();
table.getSelectionModel().addListSelectionListener(this);
super.show();
private void selectRow()
int index = combo.getSelectedIndex();
System.out.println("selecting row in table: "+index);
if (index == -1) return;
table.setRowSelectionInterval(index,index);
public void valueChanged(ListSelectionEvent e) {
combo.setSelectedIndex(table.getSelectedRow());
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == e.DESELECTED) return;
table.getSelectionModel().removeListSelectionListener(this);
selectRow();
table.getSelectionModel().addListSelectionListener(this);
private class PopupTableModel extends AbstractTableModel
public int getColumnCount()
return 1;
public int getRowCount()
return combo.getItemCount();
public String getColumnName(int columnIndex)
return "Items";
public boolean isCellEditable(int row, int col)
return false;
public Object getValueAt(int r,int c)
return combo.getItemAt(r);
import javax.swing.*;
import javax.swing.plaf.basic.*;
public class MyComboUI extends BasicComboBoxUI {
protected ComboPopup createPopup() {
return new TableComboPopup(comboBox, this);
public JList getList()
return listBox;
} -
Newbie: JTable & JComboBox
Hya,
As in the jtable tutorial I have created a JComboBox to present some data.
How can I call a method or do something when this combo box is used to changed the value.
e.g.
If the table column can have 3 values "Ms", "Miss" and "Mr" how can know when its changed and what is has changed to ?
just have a JOptionPane.showMessage( "MR was selected.") or something like that ?
thanks in advanceUse a TableModelListener
http://forum.java.sun.com/thread.jspa?threadID=527578&messageID=2533357 -
JTable - JComboBox/List - JTable
My target: I would like to have multiple columns in my comboBox or list. When I choose one item, the result would be just a single column but not all columns. Moreover, the whole comboBox is actually one cell within a JTable. i.e. when I click one cell of a jtable, it shows a comboBox.
I have searched this forum but just found some ways to get multiple columns in comboBox, and it seem no one has tried to include it in a JTable cell. I just wonder if anyone can help and it would be thankful.Let me post the code here:
//the init of comboBox model within jtable here
private void initSupplierCombo(TableColumn col){
String query = "select supplier_no, supplier_name from supplier_master group by supplier_no,supplier_name;";
JComboBox comboBox = new JComboBox();
Vector supplierList = itemDB.getComboResults(query);
try {
comboBox.setModel(new ResultSetComboBoxModel(supplierList));
col.setCellEditor(new DefaultCellEditor(comboBox));
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText(
"Click for combo box & choose");
col.setCellRenderer(renderer);
//Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = col.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
( (DefaultTableCellRenderer) headerRenderer).setToolTipText(
"Click to see a list of choices");
catch (Exception e) {
e.printStackTrace();
//ResultSetComboBoxModel
import javax.swing.*;
import java.sql.*;
import java.util.Vector;
public class ResultSetComboBoxModel extends ResultSetListModel
implements ComboBoxModel
protected Object selected = null;
public ResultSetComboBoxModel(Vector columnResults) throws Exception {
super(columnResults);
public Object getSelectedItem() {
return selected;
public void setSelectedItem(Object o) {
if(o==null)
selected = o;
else{
String value = (String) o;
selected = (Object)(value.substring(0,value.lastIndexOf(" // ")));
//ResultSetListModel
import javax.swing.*;
import java.util.*;
import java.sql.*;
public class ResultSetListModel extends AbstractListModel {
List values = new ArrayList();
public ResultSetListModel(Vector columnResults) throws Exception {
for(Iterator item = columnResults.iterator();item.hasNext();){
String[] value = (String[])item.next();
values.add(value[0] + " // " + value[1]);
public int getSize() {
return values.size();
public Object getElementAt(int index) {
return values.get(index);
} -
JTable JComboBox appears a few bits left than the cell
Hi,
I 'm using the following code to display a JComboBox in the 4th column of my JTable.
TableColumn tableColumn = table.getColumnModel().getColumn(3);
String[] values = {"", "ASC", "DESC"};
tableColumn.setCellEditor(new DefaultCellEditor(new JComboBox(values)));
JScrollPane scrollPane = new JScrollPane(table);
mainContainer.setLayout(new BorderLayout());
mainContainer.add(BorderLayout.CENTER, scrollPane);
The strange thing is that when I click on the combo box to select a value, the combo box appears a few pixels on the left of the cell that I edit, and not exaclty under it. Has anybody else encountered such a problem?
| ASC | <---------- table cell
| |
| ASC | <---------- combo box
| DESC |
Thanks in advance.
John.Hi,
I 'm using the following code to display a JComboBox in the 4th column of my JTable.
TableColumn tableColumn = table.getColumnModel().getColumn(3);
String[] values = {"", "ASC", "DESC"};
tableColumn.setCellEditor(new DefaultCellEditor(new JComboBox(values)));
JScrollPane scrollPane = new JScrollPane(table);
mainContainer.setLayout(new BorderLayout());
mainContainer.add(BorderLayout.CENTER, scrollPane);
[/code/
The strange thing is that when I click on the combo box to select a value, the combo box appears a few pixels on the left of the cell that I edit, and not exaclty under it. Has anybody else encountered such a problem?
| ASC | <---------- table cell
| |
| ASC | <---------- combo box
| DESC |
Thanks in advance.
John. -
How can I solve this nested IView / empty dropdown problem?
Hello VC experts,
I've got a VC model with a nested IView that contains drop down lists.
As long as the nested IView was only used in one place, everything was fine.
Then I used the nested IView in a second place, and this caused the following problems: After deployment, the dropdowns were empty in the place where the nested IView was already used previously, in the second place everything was OK. The dropdowns display an empty field, and when I click on them as if to select an item it 'drops down' but again there's just one line that is empty, i.e. white.
Did you experience this before?
How can I solve this?
Kind regards,
FlorianHello,
Just had the idea that I could try posting the .gml file in here. Lets see if that works.
<?xml version="1.0" encoding="utf-8"?>
<GMLPACK kit="EP" version="700.11" build="0027" model_name="error_dropdown_nestediview" model_schema_version="1.01" reserved="VisualComposer04"><GMLUNITS><AAA3FUF name="error_dropdown_nestediview" modified="14/01/2008 12:00:37" metadata="LOGLOCATION:" orig_guid="GM127189c0daec11dca6307abae1e458be"><AAD3FUG name="iView 3FUG" parent="AAA3FUF" win_type="SUB" win_scale="AUTO" win_layout="AUTO" win_pattern="STD" win_navigator="STD1" win_caption="true" pos="700 175" author="Public" modified="14/02/2008 12:29:06" orig_guid="GM0c091400daf011dc9e907abae1e458be"><ACA3FUH name="Form1" parent="AAD3FUG" box_style="0" box_features="TTL EDT" box_size="320 160" form_layout="ABS" labels_align="BEFORE" overflow="EXC" pos="550 210" box_pos="8 8" orig_guid="GM0c091401daf011dcbb437abae1e458be" fields="{DD:{type:'10',add:'V',ctl:'8',show:'Y',text:'Dd',dsg:'15',ownEnum:'#ID[AXC3FUK]',useEnum:'#ID[AXC3FUK]',pos:'100 8',size:'120 16'}}"><AEA3FUI name="in" parent="ACA3FUH" role="IN" spec="UI_OBJ_IN" anchor="L15" pos="0 15" orig_guid="GM0c091402daf011dcbc867abae1e458be"/><AEA3FUJ name="out" parent="ACA3FUH" role="OUT" spec="UI_OBJ_OUT" anchor="R15" pos="80 15" orig_guid="GM0c091403daf011dcbf157abae1e458be"/><AXC3FUK name="ENUM[ACA3FUH:DD]" parent="ACA3FUH" enumMap="apple:apple;orange:orange" orig_guid="GM0c091404daf011dcb5a97abae1e458be"/></ACA3FUH></AAD3FUG><AAD3FUL name="iView 3FUL" parent="AAA3FUF" win_type="TOP" win_scale="AUTO" win_layout="AUTO" win_pattern="STD" win_navigator="STD1" win_caption="true" pos="435 235" author="Public" modified="14/02/2008 12:29:06" orig_guid="GM0c091405daf011dcaad47abae1e458be"><ACG3FUM name="iView 3FUG" parent="AAD3FUL" box_style="0" box_features="TTL" box_size="680 328" pos="445 200" box_pos="8 8" trg_unit="#ID[AAD3FUG]" orig_guid="GM0c091406daf011dca6c97abae1e458be" fields="{}"/><ACG3FUN name="iView 3FUG" parent="AAD3FUL" box_style="0" box_features="TTL" box_size="680 336" pos="660 200" box_pos="8 344" trg_unit="#ID[AAD3FUG]" orig_guid="GM0c091407daf011dca0567abae1e458be" fields="{}"/></AAD3FUL></AAA3FUF></GMLUNITS><enums/><IMAGES/><TRANSPORTLOG/></GMLPACK>
I think if you save this as 'error_dropdown_nestediview.gml' you could reimport it into your model.
Lets see.
Best regards,
Florian -
UWL Configuration Wizard shows empty dropdown
Dear experts,
We tried to Customize the look of the UWL main page. But we are unable to see the tabs in dropdown list.
our portal version -
NW 7.0 EHP2
please suggest me on this.
Thanks
VeeranjiHi Veeranji,
This is happening probably because there is overriding of the root navigation node. This is quite easy to test. With every xml file (other than the standard ones which are all with low priority), remove one by one then check the configuration wizard again. Once you do this and remove the faulty file, you will be able to see the tabs and the Navigation node Main in the dropdown. If you have a look on the wiki page: http://wiki.sdn.sap.com/wiki/x/ehU --> it also mentions how to solve this issue.
Best Regards,
Beth Maben
EP - Senior Support Consultant II
SAP Active Global Support
Global Support Centre Ireland
**SDN Forum Moderator:
SAP Enterprise Portal: Application Integration
**SDN Universal Worklist Wiki:
http://wiki.sdn.sap.com/wiki/x/ehU -
JComboBox - delaying the dropdown list
Does anyone know how to delay the population of a JComboBox's list until the user clicks the down arrow?
In effect:
1) the user clicks the arrow on the comboBox
2) the wait cursor appears (no drop-down yet)
3) the list gets built (still no drop-down)
4) the data retrieval is done, the drop-down list is then shown, and the cursor returns to normalThe size of the popup is based on the number of elements in the
combobox before the model was rebuilt. We need to reset the popup
when the number of items in the combobox changes.That seemed to do the trick. I don't know what I was trying originally before I posted for help, but when I called hidePopup() or showPopup() from within the popupMenuWillBecomeVisible() method, I was getting a stacktrace out the wazoo.
Thanks for all of the ideas. Here's a completed example in case someone wants to refer to this later. I even added a sleep() call in the rebuildList method to simulate a long transaction, so that you can see the effect of the delay:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
public class DelayedComboBoxTest extends JFrame
private JCheckBox chkA = new JCheckBox("A");
private JCheckBox chkB = new JCheckBox("B");
private JCheckBox chkC = new JCheckBox("C");
private JComboBox cboItems = new JComboBox();
public DelayedComboBoxTest()
super("Delayed ComboBox Test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p = new JPanel();
p.add(chkA);
p.add(chkB);
p.add(chkC);
p.add(cboItems);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(p);
pack();
cboItems.addPopupMenuListener(new MyPopupMenuListener());
private void rebuildList()
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Vector items = new Vector();
if (chkA.isSelected()) { items.add("A"); }
if (chkB.isSelected()) { items.add("B"); }
if (chkC.isSelected()) { items.add("C"); }
cboItems.setModel(new DefaultComboBoxModel(items));
try
new Thread().sleep(1500); // simulate a long transaction
catch (InterruptedException ex) {}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
public static void main(String[] args)
JFrame f = new DelayedComboBoxTest();
f.setVisible(true);
class MyPopupMenuListener implements PopupMenuListener
public void popupMenuCanceled(PopupMenuEvent e) {}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
public void popupMenuWillBecomeVisible(PopupMenuEvent e)
int items = cboItems.getItemCount();
rebuildList();
if (items != cboItems.getItemCount())
cboItems.hidePopup();
cboItems.showPopup();
}One downside though: typically, a change in one of the trigger fields' content (the 3 checkboxes in this case) would cause the list to be rebuilt. It's there where you can check to see if the previously selected item in the list is contained in the new list. If so, reselect it, otherwise clear the selection. In other words, if the old value is still valid, keep it selected.
In this new way, the old value remains selected even if it's logically bad. On save, one would have to query if the selected value is still valid based on the criteria of the other trigger fields. Yeah, it's an extra step, but I don't mind doing an inexpensive hit once (on save) rather than an expensive one several times as each of the trigger fields is changed (of which could be many)
Maybe you are looking for
-
External Toshiba drive won't work on Mac after using on PC
My Toshiba External USB drive stopped working on my Mac air after I downloaded some files on a PC. It worked numerous times on the PC and then I brought it back home to use on Mac. Now, it won't show up on finder but can be found on Disk utility. I c
-
Installer works once, but never again
I created an installer using PackageMaker. This package installs my app bundle and a local copy of postgres 9.1. I also created an uninstaller that runs the Postgresql un-installer script, removes my app bundle and uses pkgutil to "forget" the receip
-
Printing old photos from IPhoto
Hello! I'm trying to print some old photos to create a printed photo album. I have all the photos in IPhoto and they are all .jpg. However when I click on some of them an exclamation mark comes up and I can't transfer them to a memory stick. I'd b
-
IPod Video 30gb volume indicator blank
The blue bar that indicates volume on my iPod is not there. When I adjust the volume it works fine as in the volume gets louder or quieter but there is no blue bit to indicate the volume level. Will a restore fix this or is it faulty? Ta x
-
My apps won't update on my iPad 1.
My apps won't update on my iPad 1. I tried resetting the iPad and updating it on my iTunes. They say they are waiting and in the meantime I can't use those apps at all.