0

Вопрос: как сделать расширяемый ComboBox? Чтобы при расширении окна мышкой, ComboBox тоже расширялся. Требуется чтобы обязательно слева от ComboBox был Label.

Код: (fxml)

<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
  <AnchorPane>
     <children>
        <Label text="Label" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
     </children>
  </AnchorPane>
  <AnchorPane>
     <children>
        <ComboBox AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
     </children>
  </AnchorPane>
</children>
</HBox>

2 ответа 2

0

AnchorPane для таких задач не подходит. Вам необходимо использовать другой контейнер, например, BorderPane.

Пример fxml:

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

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <left>
      <Label text="Label" BorderPane.alignment="CENTER" />
   </left>
   <center>
      <ComboBox maxWidth="1.7976931348623157E308" prefWidth="150.0" BorderPane.alignment="CENTER" />
   </center>
</BorderPane>
1
  • спасибо, нашел ответ через HBox, думаю BorderPane будет громоздко, хотя и интересно что у BorderPane это поведение есть по умолчанию.
    – Log1c
    22 июн 2016 в 15:12
0
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
  <AnchorPane HBox.hgrow="NEVER">
     <children>
        <Label text="Label" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
     </children>
  </AnchorPane>
  <AnchorPane HBox.hgrow="SOMETIMES">
    <children>
        <ComboBox AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
     </children>
  </AnchorPane>
</children>
</HBox>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.