JavaFX-为什么有时按钮会缩小?

时间:2018-07-04 21:35:37

标签: java button javafx

在javaFX中,为什么将鼠标悬停在它们上时我的按钮有时会随机收缩?

Database File Format

为什么会发生这种情况以及如何阻止它。

这是我描述的按钮的代码,但是我不知道您是否需要它。它似乎也发生在其他按钮上,并且并不总是发生在同一按钮上。

btnNext = new Button(">");
    btnNext.setOnAction(e -> {
        switch (view) {
            case MONTH:
                setDisplay(target.plusMonths(1));
                break;
            case WEEK:
                setDisplay(target.plusWeeks(1));
                break;
        }
    });

这只会在我单击它然后离开后发生。程序第一次启动时,它是正常大小。

1 个答案:

答案 0 :(得分:1)

当控件缩小时,通常这是一个好兆头,表明其他东西正在窃取远离它的空间。在正常情况下,import bs4 def add_custom_plotly_events( filename, events = { "plotly_click": "function plotly_click(data) { console.log(data); }", "plotly_hover": "function plotly_hover(data) { console.log(data); }" }, prettify_html = True ): # what the value we're looking for the javascript find_string = "Plotly.newPlot" # stop if we find this value stop_string = "then(function(myPlot)" def locate_newplot_script_tag(soup): scripts = soup.find_all('script') script_tag = soup.find_all(string=re.compile(find_string)) if len(script_tag) == 0: raise ValueError("Couldn't locate the newPlot javascript in {}".format(filename)) elif len(script_tag) > 1: raise ValueError("Located multiple newPlot javascript in {}".format(filename)) if script_tag[0].find(stop_string) > -1: raise ValueError("Already updated javascript, it contains:", stop_string) return script_tag[0] def split_javascript_lines(new_plot_script_tag): return new_plot_script_tag.string.split(";") def find_newplot_creation_line(javascript_lines): for index, line in enumerate(javascript_lines): if line.find(find_string) > -1: return index, line raise ValueError("Missing new plot creation in javascript, couldn't find:", find_string) def join_javascript_lines(javascript_lines): # join the lines with javascript line terminator ; return ";".join(javascript_lines) def register_on_events(events): on_events_registration = [] for function_name in events: on_events_registration.append("myPlot.on('{}', {})".format( function_name, function_name )) return on_events_registration # load the file with open(filename) as inf: txt = inf.read() soup = bs4.BeautifulSoup(txt, "lxml") new_plot_script_tag = locate_newplot_script_tag(soup) javascript_lines = split_javascript_lines(new_plot_script_tag) line_index, line_text = find_newplot_creation_line(javascript_lines) on_events_registration = register_on_events(events) # replace whitespace characters with actual whitespace # using + to concat the strings as {} in format # causes fun times with {} as the brackets in js # could possibly overcome this with in ES6 arrows and such line_text = line_text + ".then(function(myPlot) { " + join_javascript_lines(on_events_registration) +" })".replace('\n', ' ').replace('\r', '') # now add the function bodies we've register in the on handles for function_name in events: javascript_lines.append(events[function_name]) # update the specific line javascript_lines[line_index] = line_text # update the text of the script tag new_plot_script_tag.string.replace_with(join_javascript_lines(javascript_lines)) # save the file again with open(filename, "w") as outf: # tbh the pretty out is still ugly af if prettify_html: for line in soup.prettify(formatter = None): outf.write(str(line)) else: outf.write(str(soup)) 会询问所有后代节点自己需要渲染多少空间-SceneprefWidth就是这样做的。

当存在空间限制时,大多数prefHeight子类(请注意Pane子类根据某些规则管理子代)将尝试减小一个或多个子代的大小。如果您不希望特定的Pane缩小到其计算得出的大小以下,则必须 指定Node和/或minWidth或进行设置到minHeight。将其中一个或两个都设置为USE_PREF_SIZE会告诉父节点该节点一定不能收缩。

但是,如果为所有节点指定USE_PREF_SIZE,则父节点会遇到麻烦-已被告知要收缩,但不能收缩任何东西。我不知道会发生什么,但是很可能整个UI看起来都很奇怪。