I'm writing a simple WebBrowser application and i would like to have a search bar at the top of the window. The root of my stage is a TabPane that currently has only one tab.
stage = new PrimaryStage{
scene = new Scene{
minHeight = 600
minWidth = 600
root = tabPane
}
}
with its content set to a BorderPane returned by a method initBrowser
:
def initBrowser: BorderPane = new BorderPane{
top = initToolBar
center = new StackPane()
}
And then i define ToolBar in initToolBar
def initToolBar: ToolBar = new ToolBar{
prefHeight = 10
prefWidth = 10
val buttonContainer = new HBox{
padding = Insets(2, 2, 2, 2)
val b = new Button{
text = "Search"
}
children.add(b)
}
val queryTextContainer = new HBox{
padding = Insets(2, 2, 2, 2)
val querytext = new TextArea{
maxHeight = 10
}
children.add(querytext)
}
items.addAll(
buttonContainer,
new Separator(),
queryTextContainer
)
}
This is the result that i am getting
And this is without the TextArea(but looks better)
When exclude the TextArea I the ToolBar looks fine but as soon as I Add the TextArea I run into sizing problems. I am very new to Javafx and I am hoping to improve the look of my Toolbar. I have tried setting prefHeight, maxHeight, etc. but so far this has not worked. So Specifically what i am asking is how can i make my Toolbar look like the one in the second image i posted but still contain a TextArea, creating a web browser address bar? I am using Scala and ScalaFX. I would appreciate any help or direction on this. Thank you.
I've updated the code for my initToolBar method:
def initToolBar: ToolBar = new ToolBar{
prefHeight = 40
maxHeight = 40
padding = Insets(10, 10, 10, 10)
val b = new Button{
text = "Search"
prefHeight = 20
margin = Insets(10, 0, 10, 0)
}
val t = new TextArea{
prefHeight = 10
maxHeight = 10
margin = Insets(10, 0, 10, 0)
}
items.addAll(b, new Separator(), t)
}
And here is a photo of current results: doesn't fit toolbar