Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBoxes without DropDown buttons?  RSS feed

 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a head scratcher. I created a JDialog in which I add JComboBox'es. The dialog is meant to add a new project definition by the user. While creating I saw all of a sudden that the DropDown buttons are missing. If I comment out the code that fills the content of the JComboBox'esthe DropDown buttons appear again.

When I comment out the code below to "getProjectNumbersBox" the JComboBox'es have DropDown buttons:


When I call the method "getProjectNumbersBox" this results in JComboBox'es WITHOUT DropDown button


But "getProjectNumbersBox" does what it needs to do, fill the JComboBox with values:
http://s24.postimg.org/4h1zlv33l/Nieuw_Record_contents.png

This code loads the first JComboBox with the customer name (eg. ACME Inc.). This code does not remove the DropDown button:

This code loads the contents for the first JComboBox. Because of this code the DropDown button does not appear:

Does anyone know why the DropDown button is removed from my JComboBox?
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post a proper SSCCE that demonstrates the problem. While creating the SSCCE you will probably find your problem.
 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SSCCE



With the supporting class ProjectDef:

Which resulted in (after some pulling on the edges):


To the right of p10001 and Roadrunning there should have been drop down boxes.

Edit: Did some comment cleaning
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that mean you have solved the problem?
 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Does that mean you have solved the problem?


No. The second and third JComboBox have no drop down button.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which case don't know.

Did you know that the first S is SSCCE means short? I don't think that code counts as short, I am afraid.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SSCCE


No, that is NOT a SSCCE. That is a dump of your application.

The point of a SSCCE is for force you to do basic debugging by removing code not directly related to the problem.

Your question is about the missing button in the combo box.

Therefore:

1) the OK, Escape buttons are irrelevant and should not be included
2) the data in the combo boxes is irrelevant so get rid of the complex logic
3) the first, third and fourth combo boxes are irrelevant. (if you figure out why the second doesn't work then you likely have the same problem with the third), so get rid of the code related to those items
4) the ProjectDef class is irrelevant.

Once you do all that you are left with a SSCCE that might be 30 lines of code which makes it far more likely someone will take the time to read the code since YOU have made an effort to simplify the problem.

The SSCCE will still be compilable and executable. So you start with your code. Through out unnecessary code and make sure it still compiles and demonstrates the problem. Repeat until the code is a small and as relevant as possible.

If you get rid of all the irrelevant code you are left with a method something like:



I'll let you figure out what the problem is now that you can see the forest through the trees.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read your answer.


Then why haven't your replied?

I was quite upset with it.


Why?

1. I took the time to better explain what a SSCCE is and I gave you specific examples of what NOT to include in a SSCCE. That goes above and beyond what is required in an answer

2. I then took the method in question and removed all the unnecessary code. It you replace your code with my 3 lines of code you will see that the problem still exists. So I showed you how easy it is to simply code and create a proper SSCCE.

The point of a SSCCE is to start with nothing and add code until the problem shows up. So now all you have to do is remove those 3 lines of code and see if the problems exists (it won't). Then you add back in the 3 statements one at a time until the problem appears. Now you know that the problem is. That was my point about seeing the forest through the trees. It should be apparent which one of the 3 statements is causing the problem.

Instead of answering I decided to try it with another approach.


So why should I (we) bother so answer your questions if you can't take the time to say thank you?
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DH:

Rob Camick probably gives more help on this GUIs forum than anybody else. It looks as though you have caused offence both here and in your other thread. RC has given you good advice and you appear not to have taken it. If you are asked for an SSCCE, either provide an SSCCE or explain why there is difficulty with it. If you are provided with advice, follow that advice. If you have difficulty ask for more details. RC is very direct the way he talks to people, so you know where you stand. There is no pretence.

I would have thought maybe an apology would be in order.
 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:DH:

Rob Camick probably gives more help on this GUIs forum than anybody else. It looks as though you have caused offence both here and in your other thread. RC has given you good advice and you appear not to have taken it. If you are asked for an SSCCE, either provide an SSCCE or explain why there is difficulty with it. If you are provided with advice, follow that advice. If you have difficulty ask for more details. RC is very direct the way he talks to people, so you know where you stand. There is no pretence.

I would have thought maybe an apology would be in order.


Your absolutely right. My sincere apologies to Rob. I know Rob is working hard to help people with GUI problems. Both on forums and his website. That was the reason I was not eager to answer him to my other thread. I have learned to tread lightly in my reactions not to give offence.
 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
The SSCCE


No, that is NOT a SSCCE. That is a dump of your application.

The point of a SSCCE is for force you to do basic debugging by removing code not directly related to the problem.

Your question is about the missing button in the combo box.

Therefore:

1) the OK, Escape buttons are irrelevant and should not be included
2) the data in the combo boxes is irrelevant so get rid of the complex logic
3) the first, third and fourth combo boxes are irrelevant. (if you figure out why the second doesn't work then you likely have the same problem with the third), so get rid of the code related to those items
4) the ProjectDef class is irrelevant.

<SNIP>



I'll let you figure out what the problem is now that you can see the forest through the trees.


I looked into the problem you posed. Here is what I hope is more a SSCCE

When your run the code this will result in the screencapture of the "DisappearingComboBoxButtons" (I added the red arrow):
.

Again my apologies to Rob for not coming back with the required code.
 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I think I have found the reason of my problem. Line 68 of my last code (projectNumbersBox.removeAll();) is commented out. If you remove those slashes, you get the image posted in my previous post. If you add remove them the drop down button of the second JComboBox reappears.

Edit:
removeAll() is from java.awt.Container. It should have been removeAllItems().

Rob, thanks for let me find the problem myself.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I hope is more a SSCCE


Yes and it becomes easier with time as you learn to better understand what the problem is your are trying to solve.

The dialog is meant to add a new project definition by the user.


Above was part of your original problem definition. The problem is we don't know about your real application. We don't know what "project definition" data is. The vast majority of time your real application data is not important nor does it matter where you get the data from (database, file, etc), so you can just hard code simple data to show the problem.

In this example your where trying to:

1. clear the data in the combo box
2. add new data to the combo box

Once you realize the data itself is not important you forget about your real application and try to reproduce the two logic step in the simplest way possible.

That is why I suggested to remove all the complex logic that loaded the data into the combo box. That logic hid the removeAll() method. (I missed it the first time I looked at the code because I don't have time to read every single line of code to try to understand what your logic is doing. )

Sometimes its hard to notice typos like removeAll(...) vs removeAllItems(...) when there is so much code in the method.

Your last SSCCE (if you didn't notice the problem while creating the SSCCE) would have given us far less code to look at and would increase the likelihood that we would notice the difference.

Glad the problem is solved.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!