Hello

I had also had this posted at another form but haven't been getting too much of a reply base...
forums.sun.com MessageID 10375594

I'm tring to setup a JPanel using a style object for formating, JPanel.setLogicalStyle(styleimade);, and I have everything working beautifuly for a left alligned panel, but when I attempt to work with tabs on a panel that is right aligned, StyleConstants.setAlignment(styleimade, ALIGN_RIGHT), I can't seem to get tabs to work at all. Using StyleConstants.setTabSet(styleimade, atabsetimade) to set the tabs. When I make my tabset it doesn't matter what I have my tabstops set to the indention doesn't change. When I set the alignment back to left, the tabs start to work.

When I try to do a search on documentation I naturally get a huge list of tabpanels, and can't seeem to find anything on this particular subject.

Any suggestions or links to other forums would be a huge help.

Thank you in advance!

Here's the compileable code to what I am tring to do.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.lang.Object.*;
import java.util.*;

//enxtends JFrame because it is a window, Implements KeyListener, ActionListener
//so it can accept keyed input.
public class testGUI extends JFrame {


//stores the device that this window is using to display itself.
GraphicsDevice device;

//both are used to store the height and width of the screen
int ScreenHeight;
int ScreenWidth;

//create a bool to hold if the screen should be fullscreen or not
boolean fullscreen = true;

//create colors to hold default colors
Color Blue;
Color Orange;
Color Black;

//create text panels that will be displayed on the screen
JTextPane TopLeft;
StyledDocument DocTopLeft;

//pass a graphics device so it knows which screen to take, the number of the
//current display so it knows what to name the window, the height of the
//current screen, and width so it can use that to set objects
public testGUI(GraphicsDevice device, String NumberOfDisplay,
int WindowHeight, int WindowWidth) {

//set the name and size of the screen.
super("Screen " + NumberOfDisplay);
setSize(800,600);

//set the screenheight and width data types
ScreenHeight = WindowHeight;
ScreenWidth = WindowWidth;

//start up everything is Design view
//initComponents();

//set the screen up
setScreen();

//setLocationRelativeTo nothing so the screen will center
setLocationRelativeTo(null);

//set the device for this window to the device passed to the class
this.device = device;

//when a close is initiated, exit
setDefaultCloseOperation(EXIT_ON_CLOSE);

//as default show the screen
setVisible(true);
}//end default constructor

public void setScreen() {

//What happens when the X is clicked
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

//set the colors for this window
Blue = new Color(0, 0, 204);
Orange = new Color(244, 143, 0);
Black = new Color(0, 0, 0);

//change backgruond color of screen
this.setBackground(Orange);
this.getContentPane().setBackground(Orange);

//.................................................. ..Settings for TopLeft Pane
//create the setup the panel
TopLeft = new JTextPane();
TopLeft.setEditable(false);
TopLeft.setFocusable(false);
TopLeft.setBackground(Orange);
TopLeft.setPreferredSize(new java.awt.Dimension(((int) (ScreenWidth * .6)), ((int) (ScreenHeight * .6))));
TopLeft.setDisabledTextColor(Black);

//set Document to TopLeft
DocTopLeft = TopLeft.getStyledDocument();

//Create a list to hold tabstops
java.util.List TabListLeft = new ArrayList();

//create a tabstop, using the screen as a reference
TabStop tstop = new TabStop(((int) (ScreenWidth * .25)), TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
TabListLeft.add(tstop);

//create another tab stop
tstop = new TabStop(((int) (ScreenWidth * .33)), TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
TabListLeft.add(tstop);

//creating tab stop
tstop = new TabStop(((int) (ScreenWidth * .41)), TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
TabListLeft.add(tstop);

//create a tab
tstop = new TabStop(((int) (ScreenWidth * .49)), TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
TabListLeft.add(tstop);

// Create a tab set from the tab stops that were made above
TabStop[] TabStopsLeft = (TabStop[])TabListLeft.toArray(new TabStop[0]);
TabSet TabsLeft = new TabSet(TabStopsLeft);

// Add the tab set to the logical style;
// the logical style is inherited by all paragraphs
Style StyleTopLeft = TopLeft.getLogicalStyle();
StyleConstants.setAlignment(StyleTopLeft, StyleConstants.ALIGN_RIGHT);
StyleConstants.setTabSet(StyleTopLeft, TabsLeft);
TopLeft.setLogicalStyle(StyleTopLeft);

//add styles to document, in this case, it is just fonts formating
addStylesToDocument(DocTopLeft);


//insert text into the JPanels
try{
//start with text pane at top left
DocTopLeft.insertString(TopLeft.getCaretPosition() , "Test", DocTopLeft.getStyle("titles"));
DocTopLeft.insertString(TopLeft.getCaretPosition() , ("\n\t" + "test\ttest\ttest"), DocTopLeft.getStyle("maintext"));
DocTopLeft.insertString(TopLeft.getCaretPosition() , "\n Test", DocTopLeft.getStyle("subtitles"));
DocTopLeft.insertString(TopLeft.getCaretPosition() , ("\t" + "test\ttest"), DocTopLeft.getStyle("maintext"));
}//end of try block for string insertion

//I know I'm cheap there is no exception catch here
//but the user doesn't edit anything so how can it be at the wrong location?!
catch(Exception e) { }

//Make a layout that is based on things added to it
GroupLayout layout = new GroupLayout(getContentPane());
//set the layout for MenuDisplayGUI to the layout created above
getContentPane().setLayout(layout);

//Left and right left and right
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.L EADING)

.addGroup(layout.createParallelGroup()

//create a sequential group that will hold all text boxes
.addGroup(layout.createSequentialGroup()


//create a paralle group to hold everyting on the left
.addGroup(layout.createParallelGroup()
.addComponent(TopLeft)
)//end of parallel group holding everything on left of screen

//.addContainerGap(1, Short.MAX_VALUE)
)//end of parallel group holding everything horizontally
));//close of layout.setHorizontalGroup

//UP AND DOWN!!! UP AND DOWN
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.L EADING)

//create a sequential group to contain the items vertically
.addGroup(layout.createSequentialGroup()

//create a paralle group to hold the items at the top of the screen
.addGroup(layout.createParallelGroup()

//add the item at the top left
.addComponent(TopLeft)
)//end of parallel group holding the two top items

//.addContainerGap(1, Short.MAX_VALUE)
)//end of sequential group holding everything vertically
);//close of setVerticalGroup

pack();

}//end member function setScreen

protected void addStylesToDocument(StyledDocument doc) {

//create the defualt style that all other styles will build off of
Style def = StyleContext.getDefaultStyleContext().
getStyle(StyleContext.DEFAULT_STYLE);

//create the baseline for your style type
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "Sans");
StyleConstants.setBold(def, true);

//create a style used for titles, set the font
Style titles = doc.addStyle("titles", regular);
StyleConstants.setFontSize(titles, ((int) (ScreenWidth * .05)));
StyleConstants.setForeground(titles, Blue);

//create a style for subtitles
Style subtitles = doc.addStyle("subtitles", regular);
StyleConstants.setFontSize(subtitles, ((int) (ScreenWidth * .025)));

//create a style for all of the rest of the text
Style maintext = doc.addStyle("maintext", regular);
StyleConstants.setFontSize(maintext, ((int) (ScreenHeight * .025)));

}//end of member class addStyleToDocument

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
}//end try block
catch (Exception ex) {
System.out.println(ex);
}//end catch block

//get the graphics enviroment for this local computer
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

//create an array of graphics devices for all the "screen devices"
//in the env Graphics enviroment
GraphicsDevice[] devices = env.getScreenDevices();

//create an integer for looping
int loop = 0;

//create a vector to hold multipe MenuDisplayGuis for systems
//that use multiple screen
Vector DisplayWindows;
DisplayWindows = new Vector();

//create a display mode which will later pass the height
//and width of the window to the MenuDisplayGUI object
DisplayMode DM;

//loop through all of the display devices on the local computer
//create a window for each screen
while( loop < devices.length ) {

//change the displaymode to the current display mode
DM = devices[loop].getDisplayMode();

//put a MenuDisplayGUI Window into the DisplyWindows vector
//for each display device that is on the computer. Pass the
//current iteration in this loop to the MenuDisplayGUI
//that is being created so it can name itself according to
//number, send the screen height and width to handle
//position of objects.
DisplayWindows.addElement(new testGUI(devices[loop],
String.valueOf(loop + 1),
DM.getHeight(), DM.getWidth()));
//iterate the loop
loop++;
}//end while loop


}//end run block
});
}//end static main

}