2

I have a Combo Box of Strings within my JavaFX Application.

When I open the ComboBox using desktop, everything is fine, works normally.

When I port to Android using javafxports, I cannot scroll, when I try, the box closes.

Here is a video of the issue: https://www.youtube.com/watch?v=YWGzKrHhZQs

GitLab Repo of code to replicate the issue: https://github.com/mattlewer/basicComboIssue/tree/master/GluonScroll

Main Class:

package com.gluonapplication;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Screen;
import javafx.stage.Stage;


public class GluonApplication extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{

        // Loads the FXML and gets the controller
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/assets/basicViewFXML.fxml"));
        Parent root = (Parent)loader.load();
        BasicView basic = loader.getController();

        // Prepare comboBox contents
        String skills[] = {"Overall", "Agility", "Attack", "Construction", "Cooking", 
         "Crafting", "Defence", "Farming", "Fishing", "Fletching", "Herblore",
         "Hitpoints", "Hunter", "Prayer", "Magic", "Mining", "Firemaking",  "Ranged", 
         "Runecraft", "Slayer",  "Smithing",  "Strength",  "Thieving", "Woodcutting" };
        // Add contents to drop down comboBox
        for(String s : skills){
            basic.comboBox.getItems().add(s); 
        }

        // Set Scene
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);

        // Set the size of our app the the size of the users screen and show
        Screen screen = Screen.getPrimary();
        Rectangle2D bounds = screen.getVisualBounds();
        primaryStage.setX(bounds.getMinX());
        primaryStage.setY(bounds.getMinY());
        primaryStage.setWidth(bounds.getWidth());
        primaryStage.setHeight(bounds.getHeight());
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Controller Class:

package com.gluonapplication;

import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;

public class BasicView{
    @FXML ComboBox comboBox;    
}

FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="335.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gluonapplication.BasicView">
   <children>
      <BorderPane prefHeight="600.0" prefWidth="335.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <center>
            <ComboBox fx:id="comboBox" onHidden="#opener" prefHeight="30.0" prefWidth="215.0" BorderPane.alignment="CENTER" />
         </center>
      </BorderPane>
   </children>
</AnchorPane>

gradle.build file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.17'  
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'        
    }
}

mainClassName = 'com.gluonapplication.GluonApplication'

dependencies {
    compile 'com.gluonhq:charm:5.0.2'
}

jfxmobile {
    downConfig {
        version = '3.8.6'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
        compileSdkVersion = 29
        buildToolsVersion = "29.0.3"

    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

AndroidManifest.xml File:

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.gluonapplication" android:versionCode="1" android:versionName="1.0">
        <supports-screens android:xlargeScreens="true"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="21"/>
        <application android:label="GluonApplication" android:name="android.support.multidex.MultiDexApplication" android:icon="@mipmap/ic_launcher">
                <activity android:name="javafxports.android.FXActivity" android:label="GluonApplication" android:configChanges="orientation|screenSize">
                        <meta-data android:name="main.class" android:value="com.gluonapplication.GluonApplication"/>
                        <meta-data android:name="debug.port" android:value="0"/>
                        <intent-filter>
                                <action android:name="android.intent.action.MAIN"/>
                                <category android:name="android.intent.category.LAUNCHER"/>
                        </intent-filter>
                </activity>

                <activity android:name="com.gluonhq.impl.charm.down.plugins.android.PermissionRequestActivity" />
        </application>
</manifest>

EDIT: After moving the ComboBox to the 'Top' section of the BorderPane, scrolling now works for the top left quarter, but not the rest, very weird behaviour https://www.youtube.com/watch?v=D6CKjlNjYh8

Matt
  • 21
  • 4
  • Never really done Android applications using Gluon / JavaFX, but maybe the problem lies in how you handle the scrolling? Mouse wheel scroll is not the same as dragging - perhaps that's what it's doing on the mobile version. – Doombringer May 27 '20 at 16:42
  • @DoombringerBG I've just added an edit. The scrolling is now partially working, so can't be the mouse wheel idea, however it's solution is a bit odd and full functionality is still not there. – Matt May 28 '20 at 15:04
  • Have you tried putting the `ComboBox` in a different layout (still centered in it)? I could be wrong, but I think it might be losing focus when the cursors exits that region for some reason. – Doombringer May 28 '20 at 15:11
  • @DoombringerBG Just tried placing the ComboBox within a VBox, with content aligned centered, instead of a BorderPane. This causes same problem as started with. I then aligned it 'top center' and I am able to scroll the full length of the drop down, but only if I scroll on the text itself, if I scroll on the white space, I again can only scroll in the top left quarter. It appears to be a combination of issues, that scrolling is only possible if the ComboBox is placed at the very top of the page, and that the text itself is treated differently to it's 'row' within the choices – Matt May 28 '20 at 16:40
  • Sounds like the problem is coming from the `ComboBox` itself. Since your `skills[]` contains only `String`s, have you considered `ChoiceBox` instead? If you don't know what the difference is, here's a link where it's explained: https://stackoverflow.com/questions/33599322/differences-between-combobox-and-choicebox-in-javafx – Doombringer May 28 '20 at 16:48
  • @DoombringerBG My actual app requires the ComboBox's functionality, I just created this with a list of Strings to make it easy to replicate the issue. – Matt May 28 '20 at 17:28
  • In that case, since you mentioned that it worked when you scroll on the text itself, try making the labels in each `Cell` in the `ComboBox` to fill said cells. Using something like `label.setMaxWidth(Double.MAX_VALUE);` and `label.setMaxHeight(Double.MAX_VALUE);`. Check this link for some ideas on how to proceed: https://stackoverflow.com/questions/45510443/how-to-scale-label-within-a-listview-in-javafx – Doombringer May 28 '20 at 18:04
  • @DoombringerBG This improves it slightly, however the problem still persists to a degree. I also still cannot place the ComboBox anywhere other than the very top of the page, otherwise I lose all functionality again – Matt May 28 '20 at 18:41
  • Damn, this sucks. Perhaps try and implement the scrolling function yourself / override it, instead of leaving it up to Gluon. You can find a few ways to do that here: https://stackoverflow.com/questions/26537548/javafx-listview-with-touch-events-for-scrolling-up-and-down I'm honestly kind of out of ideas on what might be causing this. As a last resort you can try and ask in the `Java` channel of Joshua Fluke's (GrindReel) Discord server (you can find a link to it at the bottom of the description on any of his videos). Sorry I couldn't have been more of a help, mate. – Doombringer May 28 '20 at 18:52
  • @DoombringerBG Thanks for your help and persistence, it's an annoying bug! I think I will try and make a pop-up using a scrollpane and implement it that way, if I stumble across a fix along the way, I will update – Matt May 28 '20 at 19:15

0 Answers0