Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to control TabPane Tab 'text' rotation?

908695Jan 3 2012 — edited Jan 7 2012
Hello, I am getting confused with TabPane tabs and I don't know whether the following is a bug or a feature ...

If you put the Tabs of a TabPane on Side.LEFT or RIGHT the text in a tab is always rotated, so if you don't want it rotated you need to put the text in a label with tab.setGraphic(), and you can then call tabPane.setRotateGraphic(false) - this is the default anyway.

However with side == LEFT or RIGHT I get truncated, centred text in the label, but the close buttons always appear. But if I set the min/max tab width/height to get non-truncated text, the close button only appears on the first tab. Also the screen-width and height are swapped round for LEFT and RIGHT relative to TOP and BOTTOM.

(Actually I didn't want to use the auto-close 'button' because it's non-vetoable and too easy to hit by mistake, but I found that using right-side tabs with a compound 'graphic' including my own close-button got quite tricky to lay out. Hence this initial post.)

In the following (rather crude) code, try commenting out, or leaving in, the tab-size-setting and rotating calls, to give the 4 behaviours.

This works in v 2.0.2 and 2.1 beta b7
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.TilePane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;


public class TabPaneTest
extends Application
{

TabPane[] tps = null;

public void start(Stage stage)
throws Exception
	{
	TilePane pane = new TilePane(10, 10);
	pane.setPrefColumns(2);

	tps = new TabPane[4];

	CreateTP(0, "T");
	CreateTP(1, "R");
	CreateTP(2, "B");
	CreateTP(3, "L");

	tps[0].setSide(Side.TOP);
	tps[1].setSide(Side.RIGHT);
	tps[2].setSide(Side.BOTTOM);
	tps[3].setSide(Side.LEFT);

	pane.getChildren().addAll(tps);

        Scene scene = new Scene(pane, 800, 600);
        stage.setScene(scene);
        stage.show();

	} // start


private void CreateTP(int i, String s)
	{
	TabPane tp = new TabPane();

	Tab tab1 = new Tab();	//"one");
	tab1.setGraphic(new Label(s + " tab 1"));                        //n.b. text on tab always rotates, hence using 'graphic'
	tab1.setContent(new Rectangle(200, 200, Color.RED));
	tp.getTabs().add(tab1);

	Tab tab2 = new Tab();	//"two");
	tab2.setGraphic(new Label(s + " tab 2"));
	tab2.setContent(new Rectangle(200, 200, Color.BLUE));
	tp.getTabs().add(tab2);

	tp.setStyle("-fx-border-color: black; -fx-border-width: 1");

/* try with and without this block ...

	tp.setTabMinWidth(90);
	tp.setTabMaxWidth(90);
	tp.setTabMinHeight(60);
	tp.setTabMaxHeight(60);
*/

        // and with and without this next line

	//tp.setRotateGraphic(true);

	tps[i] = tp;

	} // CreateTP


public static void main(String[] args)
	{
	Application.launch(args);
	}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2012
Added on Jan 3 2012
3 comments
2,110 views