Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Javafx editable and saveable database

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javafx editable and saveable database

    Hello,
    as you can probably tell from my mediocre program bellow, I am rather new to Java and to Javafx, I was able to make this work to a point. I would like the file that is opened to appear in the editor tab and other files I open to appear in the viewer tab if they are not being edited. From what I have looked up I think that the HTML text editor might be the one for me the only question I have is how do I implement it and the file chooser ( because I think that would work).

    package data.base;
     
    import javafx.application.Application;
    import static javafx.application.Application.launch;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.geometry.Pos;
    import javafx.scene.*;
    import javafx.scene.control.Button;
    import javafx.scene.control.Menu;
    import javafx.scene.control.MenuBar;
    import javafx.scene.control.MenuItem;
    import javafx.scene.control.PasswordField;
    import javafx.scene.control.Tab;
    import javafx.scene.control.TabPane;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.scene.paint.*;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
     
    public class DataBase extends Application {
     
        public static void main(String[] args) {
            launch(args);
        }
     
        @Override
        public void start( Stage loginStage ) {
            final int insets = 25;
     
            loginStage.setTitle( "This is a secure Database" );
     
            Group root = new Group();
            Scene scene = new Scene( root, 1900, 1000, new LinearGradient( 0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, new 
                            Stop[] {
                        new Stop( 0, Color.web( "#CC00CC" )),
                        new Stop( 0.14, Color.web( "#9966CC" )),
                        new Stop( 0.28, Color.web( "#6666FF" )),
                        new Stop( 0.43, Color.web( "#336699" )),
                        new Stop( 0.57, Color.web( "#009966" )),
                        new Stop( 0.71, Color.web( "#009933" )),
                        new Stop( 0.85, Color.web( "#00CC00" )),
                        new Stop( 1, Color.web( "#99FF99" )),
                    }));
            loginStage.setScene( scene );
            Group display = new Group();
            Group root2 = new Group();
     
            GridPane grid = new GridPane();
            grid.setAlignment(Pos.CENTER);
            grid.setHgap( 10 );
            grid.setVgap( 10 );
            grid.setPadding( new Insets( insets, insets, insets, insets ));
     
            Text scenetitle = new Text("Please Signe In.");
            grid.add(scenetitle, 60, 39 );
     
            TextField userNameText = new TextField();
            userNameText.setPromptText( "Username" );
            userNameText.setPrefColumnCount( 10 );
     
            PasswordField pwText = new PasswordField();
            pwText.setPromptText( "Password" );
            pwText.setPrefColumnCount( 10 );
     
            Button submit = new Button( "Submit" );
            submit.setOnAction(new EventHandler<ActionEvent>() {
     
                @Override
                    public void handle(ActionEvent t ) {
                        if ( userNameText.getText().equals( "marmalade" ) && pwText.getText().equals( "theHax" )) {
                            System.out.println( "Hey Louis" );
            Scene scene2 = new Scene( root2, 1900, 1000,
                    new LinearGradient( 0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, new 
                            Stop[] {
                        new Stop( 0, Color.web( "#CC00CC" )),
                        new Stop( 0.14, Color.web( "#9966CC" )),
                        new Stop( 0.28, Color.web( "#6666FF" )),
                        new Stop( 0.43, Color.web( "#336699" )),
                        new Stop( 0.57, Color.web( "#009966" )),
                        new Stop( 0.71, Color.web( "#009933" )),
                        new Stop( 0.85, Color.web( "#00CC00" )),
                        new Stop( 1, Color.web( "#99FF99" )),
                    }));
            loginStage.setScene( scene2 );
     
            MenuItem menuEditorNew = new MenuItem( "New" );
            menuEditorNew.setOnAction( new EventHandler<ActionEvent>() {
     
                @Override
                public void handle(ActionEvent t){
                    //open a new editor
                }
            });
     
            MenuItem menuEditorOpen = new MenuItem( "Open" );
            menuEditorOpen.setOnAction( new EventHandler<ActionEvent>() {
     
                @Override
                public void handle(ActionEvent t){
                    // open a file made by the editor
                }
            });
     
            MenuItem menuEditorSave = new MenuItem( "Save" );
            menuEditorSave.setOnAction( new EventHandler<ActionEvent>() {
     
                @Override
                public void handle(ActionEvent t){
                    // save the editor
                }
            });
     
            TabPane tabPane = new TabPane();
     
            Tab editor = new Tab();
            Tab mainMenu = new Tab();
            Tab viewer = new Tab();
     
            editor.setText( "Editor" );
            editor.setClosable( false );
     
            mainMenu.setText( "Main Menu" );
            mainMenu.setClosable( false );
     
            viewer.setText( "View old entries" );
            viewer.setClosable( false );       
     
            tabPane.getTabs().addAll( viewer, editor, mainMenu );
     
            final Menu menu1 = new Menu( "File" );
            menu1.getItems().addAll( menuEditorNew, menuEditorOpen, menuEditorSave );
            MenuBar menuBar = new MenuBar();
            menuBar.getMenus().add( menu1 );
            root2.getChildren().add( tabPane );
            root2.getChildren().add( menuBar );
     
                        }
                        else {
                            System.out.println( "Never will you get my secrets!!");
                            loginStage.close();
                        }
                    }
            });
     
            grid.add( userNameText, 60, 40 );
            grid.add( pwText, 60, 41 );
            grid.add( submit, 61, 39 );
     
            display.getChildren().add( grid );
            root.getChildren().add( display );
     
            loginStage.show();
        }
    }
    Last edited by tattan; July 22nd, 2014 at 05:35 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,107
    My Mood
    Mellow
    Thanks
    186
    Thanked 656 Times in 643 Posts

    Default Re: Javafx editable and saveable database

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Try posting your code correctly in code tags per the above link. PM me if that still doesn't work.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Javafx editable and saveable database

    Thanks for the link, and it worked the first time, although I also tried to post the code without it, and for some reason it would let me do it, but I used the highlights anyway.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,107
    My Mood
    Mellow
    Thanks
    186
    Thanked 656 Times in 643 Posts

    Default Re: Javafx editable and saveable database

    Thread moved.

  5. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    My Mood
    Bored
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Javafx editable and saveable database

    Anybody?

Similar Threads

  1. Making JTable Non-Editable
    By aslanali555 in forum AWT / Java Swing
    Replies: 7
    Last Post: May 31st, 2013, 11:17 AM
  2. [SOLVED] TextArea Editable value does not change
    By beer-in-box in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 21st, 2013, 01:17 PM
  3. [SOLVED] Error for JCombobox Editable
    By remedys in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 30th, 2013, 10:09 PM
  4. Editable JTable
    By ellias2007 in forum AWT / Java Swing
    Replies: 1
    Last Post: June 2nd, 2012, 02:26 PM
  5. Non-Editable DateField in J2me
    By thiruv in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: December 22nd, 2011, 04:03 AM