class is not public in my package and cannot be accessed from outside package


Question

I am using the following ControlFX project. Hence, created a Dialogs.java class in my package and pasted the code from there.

Since I am not Inside the package org.controlsfx.dialog , I have to do the following:

import org.controlsfx.dialog.LightweightDialog;

And I am getting the following error as shown in the image below: image

When I went inside the package org.controlsfx.dialog and opened, LightweightDialog.class,

I wasn't able to make the class public.

How should I overcome this situation? Please advise.

1
0
5/1/2014 11:51:33 PM

If the class is not public, it is not part of the public API, so it's not intended (or really possible) for you to use.

To use a lightweight dialog in ControlsFX, you can either use the Dialogs class API and call the lightweight() method as part of the creation of your dialog, or you can call one of the Dialog constructors which takes a flag for the lightweight property.

Here's a complete example using the Dialogs fluent API:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import org.controlsfx.dialog.Dialogs;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();
            Scene scene = new Scene(root,600,400);

            TabPane tabPane = new TabPane();
            Tab tab1 = new Tab("Tab 1");
            BorderPane tab1Root = new BorderPane();
            Button showDialogButton = new Button("Enter message...");
            VBox messages = new VBox(3);
            HBox buttons = new HBox(5);
            buttons.setAlignment(Pos.CENTER);
            buttons.setPadding(new Insets(5));
            buttons.getChildren().add(showDialogButton);
            tab1Root.setBottom(buttons);

            ScrollPane messageScroller = new ScrollPane();
            messageScroller.setContent(messages);
            tab1Root.setCenter(messageScroller);

            tab1.setContent(tab1Root);

            Tab tab2 = new Tab("Tab 2");
            tab2.setContent(new TextField("This is tab 2"));

            tabPane.getTabs().addAll(tab1, tab2);

            showDialogButton.setOnAction(event -> {
                String response = Dialogs.create()
                        .lightweight()
                        .owner(tab1)
                        .masthead("Enter a new message")
                        .message("Enter your new message:")
                        .showTextInput();
                if (response != null) {
                    messages.getChildren().add(new Label(response));
                }
            });

            root.setCenter(tabPane);

            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

Using the Dialog constructor you'd do something like this, though it's a lot more work:

// params are owner, title, lightweight:
Dialog dialog = new Dialog(someNode, "Dialog", true);
// lots of code here to configure dialog...
Action response = dialog.show();

The real beauty of ControlsFX is the very comprehensive documentation. Just check the Javadocs for Dialogs and for Dialog.

3
5/2/2014 1:50:49 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon