@@ -77,6 +77,7 @@ public class PreferencesFrame {
7777 JComboBox <String > languageSelectionBox ;
7878
7979 int displayCount ;
80+ int defaultDisplayNum ;
8081
8182 String [] monoFontFamilies ;
8283 JComboBox <String > fontSelectionBox ;
@@ -620,13 +621,19 @@ protected void applyFrame() {
620621 // The preference will have already been reset when the window was created
621622 if (displaySelectionBox .isEnabled ()) {
622623 int oldDisplayNum = Preferences .getInteger ("run.display" );
623- int displayNum = -1 ;
624+ int displayNum = -1 ; // use the default display
624625 for (int d = 0 ; d < displaySelectionBox .getItemCount (); d ++) {
625626 if (displaySelectionBox .getSelectedIndex () == d ) {
626- displayNum = d + 1 ;
627+ if (d == defaultDisplayNum -1 ) {
628+ // if it's the default display, store -1 instead of its index,
629+ // because displays can get renumbered when others are attached
630+ displayNum = -1 ;
631+ } else {
632+ displayNum = d + 1 ;
633+ }
627634 }
628635 }
629- if (( displayNum != - 1 ) && ( displayNum != oldDisplayNum ) ) {
636+ if (displayNum != oldDisplayNum ) {
630637 Preferences .setInteger ("run.display" , displayNum ); //$NON-NLS-1$
631638 // Reset the location of the sketch, the window has changed
632639 for (Editor editor : base .getEditors ()) {
@@ -719,12 +726,12 @@ public void showFrame() {
719726 sketchbookLocationField .setText (Preferences .getSketchbookPath ());
720727 checkUpdatesBox .setSelected (Preferences .getBoolean ("update.check" )); //$NON-NLS-1$
721728
722- int defaultDisplayNum = updateDisplayList ();
729+ defaultDisplayNum = updateDisplayList ();
723730 int displayNum = Preferences .getInteger ("run.display" ); //$NON-NLS-1$
724- //if (displayNum > 0 && displayNum <= displayCount) {
725731 if (displayNum < 1 || displayNum > displayCount ) {
732+ // set the display on close instead; too much weird logic here
733+ //Preferences.setInteger("run.display", displayNum);
726734 displayNum = defaultDisplayNum ;
727- Preferences .setInteger ("run.display" , displayNum );
728735 }
729736 displaySelectionBox .setSelectedIndex (displayNum -1 );
730737
0 commit comments