FXMisc / RichTextFX

Rich-text area for JavaFX
BSD 2-Clause "Simplified" License
1.21k stars 236 forks source link

CodeArea in Tab #186

Closed kanashius closed 8 years ago

kanashius commented 9 years ago

When I put CodeAreas in a Tab, the first Tab is shown correctly, the other Tabs with other CodeAreas show just the scrollbar, not the content. I think its the Problem, that they are marked at invisible and need to be set to visible (FIX: override setVisible, so that the content is visible, too) Code:

//To set it visible
mainPane.getSelectionModel().selectedItemProperty().addListener(
                new ChangeListener<Tab>() {
                    @Override
                    public void changed(ObservableValue<? extends Tab> ov, Tab t, Tab t1) {
                        System.out.println("changed");
                        if(t!=null)
                            t.getContent().setVisible(false);
                        t1.getContent().setVisible(true);
                    }
                }
        );
//TABCLASS
public class SyntaxEditorTab extends Tab{
    private SyntaxEditor editor;
    private File file;
    public SyntaxEditorTab(Settings mainSettings){
        editor = new SyntaxEditor(mainSettings);
        this.setContent(editor);
    }
    public SyntaxEditorTab(Settings mainSettings,File tmp){
        editor = new SyntaxEditor(mainSettings);
        file=tmp;
        editor.setFile(tmp);
        this.setText(tmp.getName());
        this.setContent(editor);
    }
    public void setFile(File x){
        this.file=x;
        editor.setFile(x);
    }
    public SyntaxEditor getEditor(){
        return editor;
    }
}
//SyntaxEditorTab extends CodeArea
TomasMikula commented 9 years ago

From your description, it seems more like a problem with TabPane than with RichTextFX to me. Do you think otherwise?

kanashius commented 9 years ago

The Problem is, that TabPane set its content invisible, if the Tab is not shown. If the Tab changes, only the Scrollbars are set to visible (not recursive to the StyledTextArea, I think.) Maybe, it can be set visible, manually? (I looked up the source and think, you use List to display the text. I think, they are not set to visible, if CodeArea is set visible). I think its just bad-made by the Tab^^

kanashius commented 9 years ago

I don´t know why, but I worked a littlebit and now its displayed... or not... Its just displayed sometimes, and sometimes not. I have no idea why, I will look for a reason... I´m loading files, when doubleclicked at a TreeView. The same File is Displayed sometimes, and Sometimes not...

kanashius commented 9 years ago

Now I found the difference. The CodeArea is displayed in Tabs, when it have no scrollbars. If there are any scrollbars and its not opened in the first tab, the content is not visible. So I don´t think, its a problem of Tabs. But I don´t know.

TomasMikula commented 9 years ago

Can you create a minimal self-contained test case that I can use to reproduce the problem?

kanashius commented 9 years ago

I uploaded it at my Webside (.zip is not allowed here). I hope it helps :) http://kanashius.de/Downloads/codeAreaExample.zip

TomasMikula commented 9 years ago

Thanks, but unfortunately I was not able to reproduce the problem. I simplified the example to a single java file. Could you please try to run this and report back whether you observe the same problem?

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;

import org.fxmisc.richtext.CodeArea;

public class RichTextFXInTabPane extends Application {

    // generate some text
    private static final String TEXT1, TEXT2;
    static {
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        for(int i = 0; i < 100; ++i) {
            for(int j = 100; j > i; --j) {
                sb1.append(i);
                sb2.append(100-i);
            }
            sb1.append("\n");
            sb2.append("\n");
        }
        TEXT1 = sb1.toString();
        TEXT2 = sb2.toString();
    }

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

    @Override
    public void start(Stage primaryStage) throws Exception{
        TabPane pane = new TabPane(
                new Tab("tab1", new CodeArea(TEXT1)),
                new Tab("tab2", new CodeArea(TEXT2)));
        primaryStage.setScene(new Scene(pane, 800, 600));
        primaryStage.show();
    }
}
kanashius commented 9 years ago

Needed to rewrite TabPane pane = new TabPane( new Tab("tab1", new CodeArea(TEXT1)), new Tab("tab2", new CodeArea(TEXT2))); , tab konstruktor error, could not create Tab with sting and codearea. I made a Screenshot: codeareaexample

TomasMikula commented 9 years ago

new Tab(String, Node) constructor is only available sine 8u40, which is also the minimum recommended version for RichTextFX. There were some text rendering issues prior to 8u40 anyway, so I strongly suggest to upgrade.

kanashius commented 9 years ago

Ok, didn´t saw that. I will update... thought I had the newest Version...

TomasMikula commented 8 years ago

Closing this as it doesn't seem to be an issue in JDK 8u40 and later.