Sample code |
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.utils.SubstanceConstants.TabTextAlignmentKind;
import test.Check;
/**
* Test application that shows the use of the
* {@link SubstanceLookAndFeel#TABBED_PANE_TEXT_ALIGNMENT_KIND} client property.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#TABBED_PANE_TEXT_ALIGNMENT_KIND
*/
public class TabbedPaneTextAlignmentKind extends JFrame {
/**
* Creates the main frame for <code>this</code> sample.
*/
public TabbedPaneTextAlignmentKind() {
super("Tabbed pane text alignment kind");
this.setLayout(new BorderLayout());
// create tabbed pane with a few tabs
final JTabbedPane jtp = new JTabbedPane();
jtp.addTab("First", Check.getIcon("flag_mexico"), new JPanel());
jtp.addTab("Second", Check.getIcon("flag_sweden"), new JPanel());
jtp.addTab("Third", Check.getIcon("flag_hong_kong"), new JPanel());
// set tabs to show on left
jtp.setTabPlacement(JTabbedPane.LEFT);
this.add(jtp, BorderLayout.CENTER);
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JCheckBox isOnLeft = new JCheckBox("Is on left");
isOnLeft.setSelected(jtp.getTabPlacement() == JTabbedPane.LEFT);
isOnLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// based on the checkbox selection, set tab placement to
// either left or right
jtp.setTabPlacement(isOnLeft.isSelected() ? JTabbedPane.LEFT
: JTabbedPane.RIGHT);
jtp.revalidate();
jtp.repaint();
}
});
controls.add(isOnLeft);
final JComboBox alignmentCombo = new JComboBox(new Object[] {
TabTextAlignmentKind.DEFAULT, TabTextAlignmentKind.ALWAYS_LEFT,
TabTextAlignmentKind.ALWAYS_RIGHT,
TabTextAlignmentKind.FOLLOW_PLACEMENT,
TabTextAlignmentKind.FOLLOW_ORIENTATION });
alignmentCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TabTextAlignmentKind alignment = (TabTextAlignmentKind) alignmentCombo
.getSelectedItem();
// based on the combo selection, set the text alignment kind
jtp.putClientProperty(
SubstanceLookAndFeel.TABBED_PANE_TEXT_ALIGNMENT_KIND,
alignment);
jtp.revalidate();
jtp.repaint();
}
});
controls.add(new JLabel("Text alignment"));
controls.add(alignmentCombo);
this.add(controls, BorderLayout.SOUTH);
this.setSize(400, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* The main method for <code>this</code> sample. The arguments are
* ignored.
*
* @param args
* Ignored.
* @throws Exception
* If some exception occured. Note that there is no special
* treatment of exception conditions in <code>this</code>
* sample code.
*/
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new SubstanceLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TabbedPaneTextAlignmentKind().setVisible(true);
}
});
}
}
The screenshot below shows tabbed pane with left placement and default
(centered) text alignment - this property is not specified:
The screenshot below shows tabbed pane with left placement and
SubstanceConstants.TabTextAlignmentKind.ALWAYS_RIGHT
text alignment:
The screenshot below shows tabbed pane with right placement and
SubstanceConstants.TabTextAlignmentKind.FOLLOW_PLACEMENT
text alignment:
|