Skip to main content

Box layout problems with preferred/min/max sizes

2 replies [Last post]
dnivra
Offline
Joined: 2007-01-11

Hi,

I'm unable to create a fixed-size panel using the Box layout. I've
tried to reimplement the Swing Converter demo -
http://java.sun.com/docs/books/tutorial/uiswing/components/panel.html -
but have been unable to figure out why the Box panel containing the
Slider and the TextField changes in size (when you change the dimensions
of the Frame) in the JavaFX version. In the Swing version, the
dimensions remain unchanged even when you resize the containing frame.

Here's my implementation of the layout of the Converter application. I'm
hoping someone can spot what I'm doing wrong.

Thanks,
Arvi

import javafx.ui.*;

public class ConversionPanel extends CompositeWidget {
}

operation ConversionPanel.composeWidget() {
return Box {
orientation: HORIZONTAL
content: [
Box {
var:self
orientation: VERTICAL
alignmentY: 0
minimumSize: bind self.preferredSize
maximumSize: bind self.preferredSize
preferredSize: bind {width:150,
height:self.preferredSize.getHeight() }
background: blue
border: EmptyBorder { right: 5 }
content: [
TextField {
columns: 6
},
Slider {
min: 0
max: 100
}
]
},
Box {
orientation: VERTICAL
background: magenta
alignmentY: 0
content: [
ComboBox {
selection: 1
cells: [
ComboBoxCell {
text: "Centimeters"
},
ComboBoxCell {
text: "Inches"
},
ComboBoxCell {
text: "Yards"
}
]
},
HorizontalStrut { width: 100 }
]
}
]
};
}

Frame {
height: 250
width: 650
content:
Box {
orientation: HORIZONTAL
background: red
border: EmptyBorder { top:5 left:5 bottom:5 right:5}
content: [
ConversionPanel {
var: self
border: TitledBorder {
title: "Metric System"
}
background: cyan
maximumSize: bind {width: 500 height:
self.preferredSize.getHeight() }
},
ConversionPanel {
var: self
border: TitledBorder {
title: "U.S. System"
}
background: cyan
maximumSize: bind {width: 500 height:
self.preferredSize.getHeight() }
},
HorizontalGlue
]
}
};

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12

Just put the Box on the FlowPanel:

[code]
Frame {
height: 250
width: 650
content: FlowPanel{
content: Box {
orientation: HORIZONTAL
background: red
border: EmptyBorder { top:5 left:5 bottom:5 right:5}
content: [
ConversionPanel {
var: self
border: TitledBorder {
title: "Metric System"
}
background: cyan
maximumSize: bind {width: 500 height:
self.preferredSize.getHeight() }
},
ConversionPanel {
var: self
border: TitledBorder {
title: "U.S. System"
}
background: cyan
maximumSize: bind {width: 500 height:
self.preferredSize.getHeight() }
},
HorizontalGlue
]
}
}
};
[/code]

dnivra
Offline
Joined: 2007-01-11

> Just put the Box on the FlowPanel:
>

Ah..thanks!