• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange Bug when changing size of JFrame using JComboBox - only on one of the Strings

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I am experiencing a strange bug with my program... I have set up a JFrame - named MyWindow - along with various JPanels. The JPanels are not called directly, they are called using Panel, although in hindsight I think this may have been a waste of time. Perhaps this could be causing my issue...

SettingsPanel is where I am having the problem. I am using JComboBox with the name resChange. The String inside resChange is named screenSizes and has 4 different options (600x400, 800x533, 1000x666, 1200x800). There is also a class called SaveLoad_Settings - as the name (hopefully) suggests this is used to Save/Load any settings saved (so far just the screen size). The JFrame is resizing correctly, the JPanels are resizing and repositioning correctly. When I select any of the different options for resChange, everything works as expected. When I select an option that is the same as already selected, 3 of the 4 options work as expected - nothing happens - however when I selected 1200x800 twice, the program freezes. It is still possible to change back to another resolution as long as I stay on the same screen. If I use Save Settings whilst under the resolution of 1200x800, the program will open, the JFrame is still set to the correct size, however the JPanels are not visible. - but only if I try to call resChange.setSelectedIndex(3). Using any number before 3 works fine.

I do not understand what could be different between the different resolutions, as everything that is carried out after the JComboBox is selected is the same - apart from the frame sizes of course...

I think I have found roughly where the problem is, but I could be wrong, hence why I'm here... I have found that if I do not call 'MyWindow - changeScreenResolution()'  from 'SettingsPanel - addScreenSizeDropDown()' the ComboBox works as expected - besides from changing the size of the screen.



I have tried using window.SetPrefferedSize, window.SetMaximumSize and window.SetMinimumSiz instead of window.SetSize, however when using these the screen does not change size...

Below is the full code I have in the SettingsPanel, SaveLoad_Settings, MyWindow and Panel. I've also uploaded a ZIP file of the entire package incase any other info is required. If other info is required please ask and I will happily update/repost with the new info. The file is uploaded as a .rar and is here if required http://s000.tinyupload.com/?file_id=48406676048379454221

Thank you for taking the time to read this post.
 
J Thompson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
J Thompson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
J Thompson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MyWindow

 
J Thompson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Panel

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Don't use AWT components in a Swing application. You should be using a JPanel, not a Canvas.

2. I see too much code that is trying to play with the minimum/maximum/preferred sizes. Swing was designed to be used with layout managers. Let the layout managers do there job and component size/location should adjust automatically.
 
J Thompson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:1. Don't use AWT components in a Swing application. You should be using a JPanel, not a Canvas.



Ok, does that also apply to changing the color of JPanels? Is there another/better way I should be choosing color using swing?


Rob Camick wrote:2. I see too much code that is trying to play with the minimum/maximum/preferred sizes. Swing was designed to be used with layout managers. Let the layout managers do there job and component size/location should adjust automatically.



Ok, I'll have a play with that too. Looking into layout managers on google - they are only used for buttons/panels/components etc? They are not used in a JFrame if I am correct?
 
J Thompson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I found an easy way to fix it... It took me long enough :S

I changed when the settings data is loaded, and I also created an if statement to check if a new screen dimension has been created... Code below for anybody interested

 
reply
    Bookmark Topic Watch Topic
  • New Topic