Java 选项卡窗格中的图标和文本
我想在TabPane中添加图标和文本,我的案例中的选项卡将在左侧对齐,如图所示。我希望达到以下目标: 选项卡中的文本应该旋转,并且应该水平对齐,而不是像图a中的那样 我想在文本中添加图标。在图b中的mspaint中编辑后,我将显示我的最终屏幕 图a。 图b。 编辑: 我跟随,但我没有得到图标,因为我想在图b,但它看起来像图c。我尝试添加以下样式,但没有更改:Java 选项卡窗格中的图标和文本,java,javafx,Java,Javafx,我想在TabPane中添加图标和文本,我的案例中的选项卡将在左侧对齐,如图所示。我希望达到以下目标: 选项卡中的文本应该旋转,并且应该水平对齐,而不是像图a中的那样 我想在文本中添加图标。在图b中的mspaint中编辑后,我将显示我的最终屏幕 图a。 图b。 编辑: 我跟随,但我没有得到图标,因为我想在图b,但它看起来像图c。我尝试添加以下样式,但没有更改: .tab-pane { -fx-tab-min-width:120px; -fx-tab-max-width:120px;
.tab-pane {
-fx-tab-min-width:120px;
-fx-tab-max-width:120px;
-fx-tab-min-height:50px;
-fx-tab-max-height:50px;
}
图c。
请考虑这个例子,你可以把这个想法应用到你的项目中,并创建你想要的Tab:
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TabPaneExample extends Application{
@Override
public void start(Stage ps) throws Exception {
VBox content = new VBox(); // create a VBox to act like a graphic content for the Tab
///////////////////////////////////////////
Label label = new Label("Text");
label.setAlignment(Pos.BOTTOM_CENTER);
ImageView icon = new ImageView(new Image("file:C:\\Users\\Yahya\\Desktop\\icon.png")); // for example
icon.setFitWidth(25); icon.setFitHeight(25); // your preference
///////////////////////////////////////////
// add the components to the VBox
// You can set the Margins between the children ..etc
content.getChildren().addAll(icon, label);
//content.setAlignment(Pos.BOTTOM_CENTER);
Tab tab = new Tab();// create a Tab object and set the Graphic
tab.setGraphic(content);
// create TabPane, set side to left
// all other values need manipulation (i.e. up to your preference)
TabPane tabPane = new TabPane(tab);
tabPane.setSide(Side.LEFT);
// just simple root to see the result
Pane root = new Pane();
root.getChildren().add(tabPane);
Scene scene = new Scene(root, 300,300);
ps.setScene(scene);
ps.show();
}
public static void main(String[] args){
launch();
}
}
更新
如果要调整选项卡注释的大小,请选择以下值,例如:
tabPane.setTabMinHeight(50);
tabPane.setTabMaxHeight(50);
tabPane.setTabMinWidth(100);
tabPane.setTabMaxWidth(100);
结果
好的,去吧。当你有问题时,请回复我们。@AndrewThompson我想我确实发布了这个问题。我想做到以下几点:我想要一匹小马不是一个问题,而我在哪里可以得到一匹小马?还是给我一匹小马?还是谁偷了我的小马?这些都是问题。如果您的问题是如何编写规范?那么它太宽了。那么我们回到你的问题是什么?@AndrewThompson用我的发现为问题添加了更多细节。样式参考@Vishrant请将代码复制粘贴到你的IDE并自己尝试:谢谢,当我将代码图标的大小从25增加到55时。setFitWidth25;icon.setFitHeight25;制表符的大小没有增加。我得到了一个大小为55的切碎图像和文本。