本文整理汇总了Java中javafx.scene.control.ContentDisplay.CENTER属性的典型用法代码示例。如果您正苦于以下问题:Java ContentDisplay.CENTER属性的具体用法?Java ContentDisplay.CENTER怎么用?Java ContentDisplay.CENTER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javafx.scene.control.ContentDisplay
的用法示例。
在下文中一共展示了ContentDisplay.CENTER属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeContentPreferredWidth
/**
* Computes the preferred width of the given container based on the content
* display.
* <p>
* This is a basically just an intermediate function which should have been
* in a base class. But this is used with an already existing class
* hierarchy, so it's not possible to directly inject it.
*
* @param pContainer the container.
* @param pContentAlignable the content alignable.
* @param pLayoutForwarding the forwarded layout.
* @param pContentSelector the content selector.
* @return the double.
*/
public static double computeContentPreferredWidth(Region pContainer, IFXContentAlignable pContentAlignable, IFXLayoutForwarding pLayoutForwarding, String pContentSelector)
{
String styleClassName = pContainer.getStyleClass().get(0);
if (pContentAlignable.getContentDisplay() == ContentDisplay.TOP || pContentAlignable.getContentDisplay() == ContentDisplay.BOTTOM
|| pContentAlignable.getContentDisplay() == ContentDisplay.CENTER)
{
Node imageView = pContainer.lookup("." + styleClassName + " *.image-view");
if (imageView == null)
{
Node text = pContainer.lookup("." + styleClassName + " *.text");
Node content = pContainer.lookup("." + styleClassName + " *." + pContentSelector);
return Math.max(text.prefWidth(-1), content.prefWidth(-1));
}
}
return pLayoutForwarding.calculatePreferredWidth(-1);
}
示例2: alignRelativeToContent
/**
* Aligns the given node according to the given settings relative to the
* anchor node.
*
* @param pAnchorNode the node that is used for alignment.
* @param pNodeToAlign the node that is going to be aligned.
* @param pContentDisplay the content display to use.
* @param pHorizontalAlignment the horizontal alignment to use.
* @param pVerticalAlignment the vertical alignment to use.
*/
public static void alignRelativeToContent(Node pAnchorNode, Node pNodeToAlign, ContentDisplay pContentDisplay, HPos pHorizontalAlignment, VPos pVerticalAlignment)
{
if (pAnchorNode == null || pNodeToAlign == null)
{
return;
}
if (pContentDisplay == ContentDisplay.CENTER || pContentDisplay == ContentDisplay.BOTTOM || pContentDisplay == ContentDisplay.TOP)
{
if (pHorizontalAlignment == HPos.LEFT)
{
pNodeToAlign.setLayoutX(pAnchorNode.getLayoutX());
}
else if (pHorizontalAlignment == HPos.RIGHT)
{
pNodeToAlign.setLayoutX(pAnchorNode.getLayoutX() + pAnchorNode.prefWidth(-1) - pNodeToAlign.getLayoutBounds().getWidth());
}
}
if (pContentDisplay == ContentDisplay.CENTER || pContentDisplay == ContentDisplay.LEFT || pContentDisplay == ContentDisplay.RIGHT)
{
if (pVerticalAlignment == VPos.TOP)
{
pNodeToAlign.setLayoutY(pAnchorNode.getLayoutY() - pNodeToAlign.getLayoutBounds().getMinY());
}
else if (pVerticalAlignment == VPos.BOTTOM)
{
pNodeToAlign.setLayoutY(pAnchorNode.getLayoutY() - pNodeToAlign.getLayoutBounds().getMinY() + pAnchorNode.prefHeight(-1)
- pNodeToAlign.getLayoutBounds().getHeight());
}
}
}
示例3: computeContentPreferredHeight
/**
*
* Computes the preferred height of the given container based on the content
* display.
* <p>
* This is a basically just an intermediate function which should have been
* in a base class. But this is used with an already existing class
* hierarchy, so it's not possible to directly inject it.
*
* @param pContainer the container.
* @param pContentAlignable the content alignable.
* @param pLayoutForwarding the forwarded layout.
* @param pContentSelector the content selector.
* @return the double.
*/
public static double computeContentPreferredHeight(Region pContainer, IFXContentAlignable pContentAlignable, IFXLayoutForwarding pLayoutForwarding, String pContentSelector)
{
String styleClassName = pContainer.getStyleClass().get(0);
if (pContentAlignable.getContentDisplay() == ContentDisplay.TOP || pContentAlignable.getContentDisplay() == ContentDisplay.BOTTOM
|| pContentAlignable.getContentDisplay() == ContentDisplay.CENTER)
{
Node imageView = pContainer.lookup("." + styleClassName + " *.image-view");
if (imageView == null)
{
Node text = pContainer.lookup("." + styleClassName + " *.text");
Node content = pContainer.lookup("." + styleClassName + " *." + pContentSelector);
if (pContentAlignable.getContentDisplay() == ContentDisplay.CENTER)
{
return Math.max(text.prefHeight(-1), content.prefHeight(-1));
}
else
{
return text.prefHeight(-1) + content.prefHeight(-1);
}
}
}
return pLayoutForwarding.calculatePreferredHeight(-1);
}
示例4: alignmentToContentDisplay
/**
* Converts the given alignment value to {@link ContentDisplay}.
*
* @param pAlignment the alignment.
* @return the appropriate {@link ContentDisplay}.
*/
public static ContentDisplay alignmentToContentDisplay(int pAlignment)
{
switch (pAlignment)
{
case IAlignmentConstants.ALIGN_BOTTOM:
return ContentDisplay.BOTTOM;
case IAlignmentConstants.ALIGN_CENTER:
return ContentDisplay.CENTER;
case IAlignmentConstants.ALIGN_DEFAULT:
return ContentDisplay.LEFT;
case IAlignmentConstants.ALIGN_STRETCH:
return ContentDisplay.CENTER;
case IAlignmentConstants.ALIGN_TOP:
return ContentDisplay.TOP;
default:
// Ignore...
}
switch (pAlignment)
{
case IAlignmentConstants.ALIGN_CENTER:
return ContentDisplay.CENTER;
case IAlignmentConstants.ALIGN_DEFAULT:
return ContentDisplay.LEFT;
case IAlignmentConstants.ALIGN_LEFT:
return ContentDisplay.LEFT;
case IAlignmentConstants.ALIGN_RIGHT:
return ContentDisplay.RIGHT;
case IAlignmentConstants.ALIGN_STRETCH:
return ContentDisplay.CENTER;
default:
// Ignore...
}
return ContentDisplay.LEFT;
}
示例5: layoutContent
/**
* Layouts a text node relative to a content node or an image view node.
* <p>
* This is a basically just an intermediate function which should have been
* in a base class. But this is used with an already existing class
* hierarchy, so it's not possible to directly inject it.
*
* @param pContainer the container.
* @param pContentAlignable the content alignable.
* @param pLayoutForwarding the forwarded layout.
* @param pContentSelector the content selector.
*/
public static void layoutContent(Region pContainer, IFXContentAlignable pContentAlignable, IFXLayoutForwarding pLayoutForwarding, String pContentSelector)
{
String styleClassName = pContainer.getStyleClass().get(0);
Node text = NodeUtil.lookup(pContainer, "." + styleClassName + " *.text");
Node imageView = NodeUtil.lookup(pContainer, "." + styleClassName + " *.image-view");
if (imageView != null)
{
pLayoutForwarding.doLayout();
LayoutUtil.alignRelativeToContent(imageView, text, pContentAlignable.getContentDisplay(), pContentAlignable.getRelativeHorizontalTextAlignment(),
pContentAlignable.getRelativeVerticalTextAlignment());
}
else if (text != null && pContentSelector != null)
{
Node content = pContainer.lookup("." + styleClassName + " *." + pContentSelector);
double width = computeContentPreferredWidth(pContainer, pContentAlignable, pLayoutForwarding, pContentSelector);
double height = computeContentPreferredHeight(pContainer, pContentAlignable, pLayoutForwarding, pContentSelector);
double modY = (pContainer.getHeight() - height) / 2;
content.autosize();
text.autosize();
if (pContentAlignable.getContentDisplay() == ContentDisplay.TOP)
{
content.relocate((width - content.prefWidth(-1)) / 2, modY);
text.relocate((width - text.prefWidth(-1)) / 2, content.prefHeight(-1) + modY);
}
else if (pContentAlignable.getContentDisplay() == ContentDisplay.BOTTOM)
{
content.relocate((width - content.prefWidth(-1)) / 2, text.prefHeight(-1) + modY);
text.relocate((width - text.prefWidth(-1)) / 2, modY);
}
else if (pContentAlignable.getContentDisplay() == ContentDisplay.CENTER)
{
content.relocate((width - content.prefWidth(-1)) / 2, (height - content.prefHeight(-1)) / 2 + modY);
text.relocate((width - text.prefWidth(-1)) / 2, (height - text.prefHeight(-1)) / 2 + modY);
}
else if (pContentAlignable.getContentDisplay() == ContentDisplay.RIGHT)
{
content.relocate(width - content.prefWidth(-1), modY);
text.relocate(0, modY);
}
else
{
pLayoutForwarding.doLayout();
}
LayoutUtil.alignRelativeToContent(content, text, pContentAlignable.getContentDisplay(), pContentAlignable.getRelativeHorizontalTextAlignment(),
pContentAlignable.getRelativeVerticalTextAlignment());
}
else
{
pLayoutForwarding.doLayout();
}
}