Box Layout, JTextFields, vertical glue, ect
How do you make it so that your text field on a graphics page dose not expand when you use Box Layout and maximise it?
thanks a lot it worked ^_^ my classmates thank you as well
Similar Messages
-
Hello,
I am having difficulty with my box layouts in my form applet.
I have a JFrame with two panels. The left panel will allow the user to enter some parameters via text boxes, drop down menus, etc for a shape, which will appear on the right panel.
To arrange the form entry boxes on the left panel, I implemented a box layout. Here is where my trouble lies. I am not sure if I am using them correctly.
In the left panel, I added a box objectentitled entrySideBox, which has a createVerticalBox() orientation. I further added 7 boxes to this box layout, which had a createHorizontalBox() orientation. I have the form elements within the array of horizontal boxes. In summary, I hoped to create a box layout column with 7 horizontal rows to house the form entry elements.
Can I do this with the Box Layout? My form elements do not appear to be appearing as expected!
I have my code below. What is wrong?
//import the necessary java classes
import java.awt.*; //for the awt widgets
import javax.swing.*; //for the swing widgets
import java.awt.event.*; //for the event handler interfaces
public class DemoShape extends JFrame
//declare private data members of the DemoShape class
//requires seven control buttons
private JTextField xShapeText, yShapeText, messageText, fontSizeText;
private JComboBox shapeTypeDrop, shapeColorDrop, fontTypeDrop,fontColorDrop;
//declare the entry and display panel containers
private Panel entryPanel;
private Panel displayPanel;
//declare public data members of the DemoShape class
//constructor to initialize private data members
public DemoShape()
//call the superclass (JFrame) constructor with the name argument
//this must be done first (as in C++)
super("DemoShape Applet");
//arrays of string to be used later in combo boxes
//some are used more than once
String fonts[] = {"Dialog", "Dialog Input", "Monospaced",
"Serif", "Sans Serif"};
String shapes[] = {"Rectangle", "Round", "Oval"};
String colors[] = {"Black", "Blue", "Cyan", "Dark Gray",
"Gray", "Green", "Light Gray", "Magenta", "Orange",
"Pink", "Red", "White", "Yellow"};
//get the content pane of the class outside
Container entire = this.getContentPane();
entire.setLayout(new GridLayout(1,2));
//create the entry panel and add it to the entire pane
//this will be 7 rows, 1 column
//each row will have a panel with the form entry elements
entryPanel = new Panel(new FlowLayout());
entire.add(entryPanel);
//create the display panel and add it to the entire pane
//this will display the output
displayPanel = new Panel();
entire.add(displayPanel);
//entry panel code
//use a box layout to add the boxes in a row fashion on the entryPanel
Box boxes[] = new Box[7];
//create a main box for the entry side
Box entrySideBox = Box.createVerticalBox();
//iterively create a box layout for each row
for(int b = 0; b < boxes.length; b++)
{ boxes[b] = Box.createHorizontalBox(); }
//add the form elements to the boxes
//the first row should have the shape label
JLabel shapeHeader = new JLabel("Enter Shape Parameters:");
boxes[0].add(shapeHeader);
//second row should have the shape type and color
JLabel shapeTypeLabel = new JLabel("Select Shape:");
boxes[1].add(shapeTypeLabel);
shapeTypeDrop = new JComboBox(shapes);
boxes[1].add(shapeTypeDrop);
JLabel shapeColorLabel = new JLabel("Select Shape Color:");
boxes[1].add(shapeColorLabel);
shapeColorDrop = new JComboBox(colors);
boxes[1].add(shapeColorDrop);
//third row should have the x and y coords
JLabel xShapeLabel = new JLabel("Enter X:");
boxes[2].add(xShapeLabel);
xShapeText = new JTextField("200", 3);
boxes[2].add(xShapeText);
JLabel yShapeLabel = new JLabel("Enter Y:");
boxes[2].add(yShapeLabel);
yShapeText = new JTextField("200", 3);
boxes[2].add(yShapeText);
//fourth row should have the message label
JLabel messageHeader = new JLabel("Enter Message Parameters:");
boxes[3].add(messageHeader);
//the fifth row should have the message
JLabel messageLabel = new JLabel("Enter Message:");
boxes[4].add(messageLabel);
messageText = new JTextField(50);
boxes[4].add(messageText);
//the sixth row should have the font type and size
JLabel fontTypeLabel = new JLabel("Select Font:");
boxes[5].add(fontTypeLabel);
fontTypeDrop = new JComboBox(fonts);
boxes[5].add(fontTypeDrop);
JLabel fontSizeLabel = new JLabel("Enter Font Size:");
boxes[5].add(fontSizeLabel);
fontSizeText = new JTextField("12", 2);
boxes[5].add(fontSizeText);
//the seventh row should have font color
JLabel fontColorLabel = new JLabel("Select Font Color:");
boxes[6].add(fontColorLabel);
fontColorDrop = new JComboBox(colors);
boxes[6].add(fontColorDrop);
//add the boxes to the entrySideBox
for(int e = 0; e < boxes.length; e++)
{ entrySideBox.add(boxes[e]); }
//add the entrySideBox to the entry panel
entryPanel.add(entrySideBox);
//display panel code
//debugging
JLabel test = new JLabel("Display Output Here");
displayPanel.add(test);
//set the size of the entire window and show the entire applet
this.setSize(800,600);
this.show();
} //end the DemoShape constructor
//call the main class
public static void main(String args[])
//create an instance of the DemoShape class
DemoShape DemoShapeRun = new DemoShape();
//add the window listener to the applet
DemoShapeRun.addWindowListener(
new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
} //end main
} //end DemoShape classThe problem with GridLayout is the form elements sizes
change relative to the size of the panel. I want the
form elements to remain in a consistent state.
Should I quit using the box layout?Ok, try to set the layout of the upper content pane to BorderLayout and place the left panel with your components in the WEST part of it (the panel for the drawings goes to CENTER). I don't know if this will produce the result that you want, but it's an idea.
You should use a GridLayout for this panel and only
specify 2 columns (don't specify the number of rowsor
the number of columns will be ignored, see theclass
documentation for further details).
Hope this helps,
Pierre2 Columns? For what?The first column is for the labels (e.g. "Select Font Color") and the second is for the input component (e.g. textarea). -
used BOX LAYOUT
I have two panels, one header having two labels
another panel inside scrollpane,
but first panel by default comes to center
so,
i set panelHeader.setAlignmentX(Component.LEFT);
now first panel comes slightly to left side but still not aligned with second panelJUst Add yout comp[onents on that panel ok
panel2 & panel 3
Panel2 is the left panel & panel3 is the right panel ok
Dear Bye
import javax.swing.*;
class layout
BoxLayout box;
JFrame frame;
JPanel panel1 , panel2 , panel3;
layout()
frame = new JFrame();
panel1 = new JPanel();
panel2 = new JPanel();
Panel3 = new JPanel();
box = new BoxLayout(panel1,BoxLayout.X_AXIS); // horizontal Layout And Y_AXIS For vertical
frame.getContentPane().add(panel1);
panel1.setLayout(box);
panel1.add(panel2);
panel1.add(panel3);
public static void main(String ss[])
layout ll = new layout();
} -
getting error
cannot resovle symbol createRigidArea location class Box
same thing is there in java tutorials pls help me.
pAnswer.add(Box.createRigidArea(new Dimension(0,5)));Here is the code which is working Fine i am working on it It's Tested Ok Injoy dear
& after Compiling this code u can able to get correct layout Then u have to chack your
PATH variable ehere u set your java PATH OK Dear Bye
import javax.swing.*;
import java.awt.*;
public class bookdata
JFrame frame;
JPanel panel , panel2 , panel3;
JButton but1,but2,but3,but4,but5,but6;
Color cc;
BoxLayout bak;
ImageIcon icon;
FlowLayout flo;
public bookdata()
icon = new ImageIcon("book/book.jpg");
frame = new JFrame("Book Database");
frame.setResizable(false);
frame.setIconImage(new ImageIcon("book/logo.gif").getImage());
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - 550)/2;
int y = (d.height - 500)/2;
frame.setBounds(x,y,400,300);
public void main1()
JLabel label = new JLabel(icon);
flo = new FlowLayout();
panel3 = new JPanel();
but1 = new JButton("NEW BOOK");
but2 = new JButton("EDIT");
but3 = new JButton("DELET");
but4 = new JButton("SHOW");
but5 = new JButton("LONE");
but6 = new JButton();
panel = new JPanel();
bak = new BoxLayout(panel,BoxLayout.Y_AXIS); // BOX Layout
panel.setLayout(bak);
// 1st 220 is for R
// 2nd 177 is for G
// 3rd 162 is for B
// 4th 255 is for Alpha
cc = new Color(51,51,255);
panel2 = new JPanel();
panel2.setLayout(flo);
panel2.setBackground(cc);
panel2.add(label);
JSeparator hh = new JSeparator(SwingConstants.VERTICAL);
SpringLayout layout = new SpringLayout();
panel3.setLayout(layout);
panel3.add(but1); // pp1
panel3.add(but2); // pp2
panel3.add(but3); // pp3
panel3.add(but4); // pp4
panel3.add(but5); // pp5
panel3.add(hh);
layout.putConstraint(SpringLayout.WEST, but1, 15,SpringLayout.WEST, panel3); // pp1
layout.putConstraint(SpringLayout.NORTH, but1, 25,SpringLayout.NORTH, panel3);
layout.putConstraint(SpringLayout.WEST, but2, 15,SpringLayout.WEST, panel3); // pp2
layout.putConstraint(SpringLayout.NORTH, but2, 55,SpringLayout.NORTH, panel3);
layout.putConstraint(SpringLayout.WEST, but3, 15,SpringLayout.WEST, panel3); // pp3
layout.putConstraint(SpringLayout.NORTH, but3, 85,SpringLayout.NORTH, panel3);
layout.putConstraint(SpringLayout.WEST, but4, 15,SpringLayout.WEST, panel3); // pp4
layout.putConstraint(SpringLayout.NORTH, but4, 115,SpringLayout.NORTH, panel3);
layout.putConstraint(SpringLayout.WEST, but5, 15,SpringLayout.WEST, panel3); // pp5
layout.putConstraint(SpringLayout.NORTH, but5, 145,SpringLayout.NORTH, panel3);
layout.putConstraint(SpringLayout.WEST, hh, 100,SpringLayout.WEST, panel3);
layout.putConstraint(SpringLayout.NORTH, hh, 500,SpringLayout.NORTH, panel3);
frame.getContentPane().add(panel);
panel.add(panel2);
panel.add(panel3);
frame.setSize(600,500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} -
Align JLabels and JTextFields vertically in different areas
I like to have 3 TitledBorders for 3 different areas of my frame.
Each area has its own components - JLabels, JTextField, etc.
How to align JLabels and JTextFields vertically in different areas?
e.g. for the following test program, how to configure label1, label2, label3 so that their right sides all align vertically and
tf1, tf2, tf3 so that their left sides all align vertically?
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
public class TitledBorderDemo extends JFrame {
public TitledBorderDemo() {
super("TitledBorderDemo");
JTextField tf1 = new JTextField("hello", 6);
JTextField tf2 = new JTextField("hello", 12);
JTextField tf3 = new JTextField("test");
JTextField tf4 = new JTextField("test2");
JLabel label1 = new JLabel("1234567890ertyuiyup label");
JLabel label2 = new JLabel("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz long label");
JLabel label3 = new JLabel("short label");
JLabel label4 = new JLabel("test");
JPanel panel_tf = new JPanel(new GridBagLayout());
JPanel panel_pf = new JPanel(new GridBagLayout());
JPanel panel_ftf = new JPanel(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints(0, 0, 3, 3,
0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(10, 10, 10, 10), 0, 0);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.anchor = GridBagConstraints.WEST;
panel_tf.add(label1, constraints);
constraints.gridx = 2;
constraints.gridwidth = 1;
constraints.anchor = GridBagConstraints.EAST;
panel_tf.add(tf1, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 2;
constraints.anchor = GridBagConstraints.WEST;
panel_pf.add(label2, constraints);
constraints.gridx = 2;
constraints.gridwidth = 1;
constraints.anchor = GridBagConstraints.EAST;
panel_pf.add(tf2, constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.anchor = GridBagConstraints.WEST;
panel_ftf.add(label3, constraints);
constraints.gridx = 2;
constraints.gridwidth = 1;
constraints.anchor = GridBagConstraints.EAST;
panel_ftf.add(tf3, constraints);
constraints.gridx = 3;
constraints.gridwidth = 1;
constraints.anchor = GridBagConstraints.WEST;
panel_ftf.add(label4, constraints);
constraints.gridx = 4;
constraints.anchor = GridBagConstraints.EAST;
panel_ftf.add(tf4, constraints);
panel_tf.setBorder(new TitledBorder("JTextField1"));
panel_pf.setBorder(new TitledBorder("JTextField2"));
panel_ftf.setBorder(new TitledBorder("JTextField3"));
JPanel pan = new JPanel(new GridLayout(3, 1, 10, 10));
pan.add(panel_tf);
pan.add(panel_pf);
pan.add(panel_ftf);
this.add(pan);
public static void main(String args[]) {
JFrame frame = new TitledBorderDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 450);
frame.setVisible(true);
}Thank you! It works!
I add some labels & components to your demo program.
Most of the components align vertically.
How to align the "Country", "Test2" & "Extension" labels on the right sides?
How to align their corresponding components so that their left sides all align vertically?
How to make the Cancel button stick to the Save button
(i.e. eliminate the gap between the Cancel and the Save button)?
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class TitledBorderDemoNew extends JFrame {
public TitledBorderDemoNew() {
super("TitledBorderDemoNew");
JLabel nameLabel = new JLabel("Name");
JTextField nameText = new JTextField(20);
JLabel addressLabel = new JLabel("Address (City & State)");
JTextField addressText = new JTextField(40);
JLabel countryLabel = new JLabel("Country");
JTextField countryText = new JTextField(30);
JLabel testLabel = new JLabel("Test");
JTextField testText = new JTextField(20);
JLabel test2Label = new JLabel("Test2");
JTextField test2Text = new JTextField(20);
JLabel phoneLabel = new JLabel("Phone");
JTextField phoneText = new JTextField(20);
JLabel extensionLabel = new JLabel("Extension");
JTextField extensionText = new JTextField(5);
JLabel postalCodeLabel = new JLabel("Postal Code");
JTextField postalCodeText = new JTextField(6);
JButton saveButton = new JButton("Save");
JButton cancelButton = new JButton("Cancel");
JButton commentButton = new JButton("Comment");
int longWidth = addressLabel.getPreferredSize().width;
GridBagConstraints constraints = new GridBagConstraints();
JPanel p1 = new JPanel(new GridBagLayout());
p1.setBorder(createBorder("Name"));
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,6,4,6);
p1.add(nameLabel, constraints);
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
p1.add(nameText, constraints);
constraints.gridx = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
p1.add(Box.createHorizontalGlue(), constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 0.0;
p1.add(Box.createHorizontalStrut(longWidth), constraints);
JPanel p2 = new JPanel(new GridBagLayout());
p2.setBorder(createBorder("Address"));
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,6,4,6);
p2.add(addressLabel, constraints);
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
p2.add(addressText, constraints);
// extra label & component
constraints.gridx = 2;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,36,4,6);
p2.add(countryLabel, constraints);
constraints.gridx = 3;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(4,6,4,6);
p2.add(countryText, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,6,4,6);
p2.add(testLabel, constraints);
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
p2.add(testText, constraints);
// extra label & component
constraints.gridx = 2;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,36,4,6);
p2.add(test2Label, constraints);
constraints.gridx = 3;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(4,6,4,6);
p2.add(test2Text, constraints);
constraints.gridx = 4;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
p2.add(Box.createHorizontalGlue(), constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 0.0;
p2.add(Box.createHorizontalStrut(longWidth), constraints);
JPanel p3 = new JPanel(new GridBagLayout());
p3.setBorder(createBorder("Phone"));
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,6,4,6);
p3.add(phoneLabel, constraints);
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
p3.add(phoneText, constraints);
constraints.gridx = 2;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,6,4,6);
p3.add(extensionLabel, constraints);
constraints.gridx = 3;
constraints.anchor = GridBagConstraints.WEST;
p3.add(extensionText, constraints);
constraints.gridx = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
p3.add(Box.createHorizontalGlue(), constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 0.0;
p3.add(Box.createHorizontalStrut(longWidth), constraints);
JPanel p4 = new JPanel(new GridBagLayout());
p4.setBorder(createBorder("Postal Code"));
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(4,6,4,6);
p4.add(postalCodeLabel, constraints);
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
p4.add(postalCodeText, constraints);
constraints.gridx = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
p4.add(Box.createHorizontalGlue(), constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 0.0;
p4.add(Box.createHorizontalStrut(longWidth), constraints);
JPanel p5 = new JPanel(new GridBagLayout());
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(4,6,4,6);
p5.add(commentButton, constraints);
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
p5.add(Box.createHorizontalGlue(), constraints);
constraints.gridx = 2;
constraints.gridwidth = GridBagConstraints.RELATIVE;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.EAST;
p5.add(cancelButton, constraints);
constraints.gridx = 3;
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.anchor = GridBagConstraints.EAST;
p5.add(saveButton, constraints);
JPanel panel = new JPanel(new GridBagLayout());
constraints.gridx = 0;
constraints.gridy = 0;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
panel.add(p1, constraints);
constraints.gridy = 1;
panel.add(p2, constraints);
constraints.gridy = 2;
panel.add(p3, constraints);
constraints.gridy = 3;
panel.add(p4, constraints);
constraints.gridy = 4;
panel.add(p5, constraints);
this.add(new JScrollPane(panel));
private Border createBorder(String title)
TitledBorder b = new TitledBorder(title);
b.setTitleColor(Color.RED.darker());
return b;
public static void main(String args[]) {
JFrame frame = new TitledBorderDemoNew();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}Edited by: 833768 on 26-Apr-2011 10:32 AM -
How to have a box layout on a JDialog, with an image set as background
Hi,
I need to have a JDialog in which there is a background image set (I already did this part, but only with the default layout). I further need to add text to the lower part of the JDialog. (For this, I guess I need to have a box layout.). I am not able to do so, because if I do so, I wont be able to set image background to the entire JDialog. Please help me out with how to solve this issue?
Thanks,
JobyHi jduprez,
Thanks for the reply. I checked Rob Camick's blog. It gives a nice way to add an image to a panel (*master panel*) and to use it.
I still have my problem open. The above solution gives panel that I can add to my JDialog. But on the bottom half of the image (as you said, BorderLayout.South), I need to add another structured set of components using a Border Layout again.!, ie, one more panel with a BorderLayout. So when I add
this panel, to the master panel containing the image, then the image gets cut off, at that point. I tried using component.setOpaque(false) on my sub-panel, still it does not work. Any idea, how to achieve this...?
Following is the code I have adapted.
public class BackgroundPanel extends JPanel
public static final int SCALED = 0;
public static final int TILED = 1;
public static final int ACTUAL = 2;
private Paint painter;
private Image image;
private int style = SCALED;
private float alignmentX = 0.5f;
private float alignmentY = 0.5f;
private boolean isTransparentAdd = true;
public static void main(String[] args) {
Image img = getImage("D:/imgs/Snowdrop.jpg");
BackgroundPanel panel = new BackgroundPanel(img);
JDialog dlg = new JDialog();
dlg.setLayout(new BorderLayout());
dlg.add(panel);
panel.setTransparentAdd(true);
Panel nPanel = new Panel();
nPanel.setLayout(new BorderLayout());
JLabel label = new JLabel();
//label.set
label.setText("<html>HI<br>This is another line<br><br><br><br><br><br><br><br><br><br></html>");
nPanel.add(label, BorderLayout.NORTH);
panel.add(nPanel/*label*/,BorderLayout.SOUTH);
dlg.setSize(600, 500);
dlg.setVisible(true);
private static Image getImage(String fileName){
File file = new File(fileName);
Image image = null;
try{
image = ImageIO.read(file);
catch(IOException ioe){
/*JOptionPane.showMessageDialog(dlg, "Error in loading image file",
"Error", JOptionPane.ERROR_MESSAGE, null);*/
return image;
* Set image as the background with the SCALED style
public BackgroundPanel(Image image)
this(image, SCALED);
* Set image as the background with the specified style
public BackgroundPanel(Image image, int style)
this(image,style,-1,-1);
* Set image as the backround with the specified style and alignment
public BackgroundPanel(Image image, int style, float alignmentX, float alignmentY)
setImage( image );
setStyle( style );
if (alignmentX > 0){
setImageAlignmentX( alignmentX );
if (alignmentY > 0){
setImageAlignmentY( alignmentY );
setLayout( new BorderLayout() );
* Use the Paint interface to paint a background
public BackgroundPanel(Paint painter)
setPaint( painter );
setLayout( new BorderLayout() );
* Set the image used as the background
public void setImage(Image image)
this.image = image;
repaint();
* Set the style used to paint the background image
public void setStyle(int style)
this.style = style;
repaint();
* Set the Paint object used to paint the background
public void setPaint(Paint painter)
this.painter = painter;
repaint();
* Specify the horizontal alignment of the image when using ACTUAL style
public void setImageAlignmentX(float alignmentX)
this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX;
repaint();
* Specify the horizontal alignment of the image when using ACTUAL style
public void setImageAlignmentY(float alignmentY)
this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY;
repaint();
* Override method so we can make the component transparent
public void add(JComponent component)
add(component, null);
* Override method so we can make the component transparent
public void add(JComponent component, Object constraints)
if (isTransparentAdd)
makeComponentTransparent(component);
super.add(component, constraints);
* Controls whether components added to this panel should automatically
* be made transparent. That is, setOpaque(false) will be invoked.
* The default is set to true.
public void setTransparentAdd(boolean isTransparentAdd)
this.isTransparentAdd = isTransparentAdd;
* Try to make the component transparent.
* For components that use renderers, like JTable, you will also need to
* change the renderer to be transparent. An easy way to do this it to
* set the background of the table to a Color using an alpha value of 0.
private void makeComponentTransparent(JComponent component)
component.setOpaque( false );
if (component instanceof JScrollPane)
JScrollPane scrollPane = (JScrollPane)component;
JViewport viewport = scrollPane.getViewport();
viewport.setOpaque( false );
Component c = viewport.getView();
if (c instanceof JComponent)
((JComponent)c).setOpaque( false );
* Add custom painting
protected void paintComponent(Graphics g)
super.paintComponent(g);
// Invoke the painter for the background
if (painter != null)
Dimension d = getSize();
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(painter);
g2.fill( new Rectangle(0, 0, d.width, d.height) );
// Draw the image
if (image == null ) return;
switch (style)
case SCALED :
drawScaled(g);
break;
case TILED :
drawTiled(g);
break;
case ACTUAL :
drawActual(g);
break;
default:
drawScaled(g);
* Custom painting code for drawing a SCALED image as the background
private void drawScaled(Graphics g)
Dimension d = getSize();
g.drawImage(image, 0, 0, d.width, d.height, null);
* Custom painting code for drawing TILED images as the background
private void drawTiled(Graphics g)
Dimension d = getSize();
int width = image.getWidth( null );
int height = image.getHeight( null );
for (int x = 0; x < d.width; x += width)
for (int y = 0; y < d.height; y += height)
g.drawImage( image, x, y, null, null );
* Custom painting code for drawing the ACTUAL image as the background.
* The image is positioned in the panel based on the horizontal and
* vertical alignments specified.
private void drawActual(Graphics g)
Dimension d = getSize();
Insets insets = getInsets();
int width = d.width - insets.left - insets.right;
int height = d.height - insets.top - insets.left;
float x = (width - image.getWidth(null)) * alignmentX;
float y = (height - image.getHeight(null)) * alignmentY;
g.drawImage(image, (int)x + insets.left, (int)y + insets.top, this);
}Thanks,
Joby -
Can you alter, or create your own photo box layouts in iMovie 11. If so how, or where can you do this.
I can't find that option. I don't want to use the canned, preset photo layouts. Any options available?It has been happening to me, but it doesn't change the final video itself, if it is previewed in full screen mode, it will sometimes freeze, but to see the scene that freezes, just play it (in fullscreen mode) and click back a few seconds before it freezes and it should play normally.
You can also bring the mouse over the clip to preview it or:
Duplicate the whole project
2. Export it to Quicktime
Hope this helps -
i know how to use a box layout on panels but i am having a problem applying box layout on jframe,
what i do basicaly is extends jframe first and then in the constructor i put setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
it gives an error that box layout cant be shared...this method works with all other layouts...
please help me and please dont tell me to go read the sun online tutorials...To speak truely. All the j2se default layout manager will be replaced by the default layoutmanager in NetBeans ---group layout manager.
I suggest you download a NetBeans IDE and start working with the new layout manager. -
How do you crop a vertical slide to a constraint size without turning it on it's side? iPhoto 6 automatically rotated the crop box for a vertical slide (picture).
Select the aspect ratio first.
Then go back to the same menu and go to the bottom and selectConstrait as portrait.
OT -
Hello,
I wondered if anyone could advise? In this code I was trying to display a column of buttons each the same size. And next to these buttons, a single button, and textfield.
Something like:
Button 1
Button 2
Button 3 "some space" SearchButton ////Text field ///
Button 4
Button 5
But when the textfield is displays it becomes the height of the 5 buttons, but the searchbutton did not. Is there any method to change the textfield to the height of the searchButton? Or could anyone possibly demonstrate a different layout manager?
Thank you
JButton button1, button2, button3, button4, button5;
JPanel panel = new JPanel(new GridLayout(0,1));
panel.add(button1 = new JButton("Button 1"));
castleGreen.addActionListener(this);
panel.add(button2 = new JButton("Button 2"));
runTown.addActionListener(this);
panel.add(button3 = new JButton("Button 3"));
highHill.addActionListener(this);
panel.add(button4 = new JButton("Button 4"));
luckNow.addActionListener(this);
panel.add(button5 = new JButton("Button 5"));
littleHaven.addActionListener(this);
Box leftCol = Box.createVerticalBox();
leftCol.add(panel);
Box rightCol = Box.createHorizontalBox();
rightCol.add(searchBt = new JButton("Search"));
searchBt.addActionListener(this);
rightCol.add(Box.createHorizontalStrut(10));
rightCol.add(searchTf = new JTextField(20));
Box topDisplay = Box.createHorizontalBox();
topDisplay.add(leftCol);
topDisplay.add(Box.createHorizontalStrut(40));
topDisplay.add(rightCol);Thank you for replying.
In my version of the code the name shown on the left
buttons are all differenet sizes. When I built these
into a vertical box, the buttons were displayed
uneven. I resolve this by using a panel.By default the system sizes buttons according to the ammount of text in them.
>
I wondered to achieve this layout, would be easier to
use a gridbaglayout?Personally I've gone right off GridBagLayout. It's complicated to use and seems unstable in resizing.
I've got much more reliable results from BoxLayout. -
I cannot see any of my text boxes in the vertical view.
I just checked the first chapter of my iBook in the vertical display. I cannot see any of my text after the section introduction page. All of it is written in text boxes that I created. I can see all of my widgets and text in the standard horizontal view but when I switch to vertical all I can see is the section introductions and the widgets off to the left hand side. This is a guide to surface palpation. Each page is its own set of instructions instead of being one long piece of continous writing. Is there a way to reformat my text boxes so that they are visible in the vertical view without starting over?
The portrait mode only supports the flow of text (and pictures pasted into the text), and widgets (they will all be positioned on the left).
You need to design in landscape mode knowing how the portrait mode works. Text boxes won't show up in portrait mode. -
Horizontal Layout scrolling vertically
Has anyone worked with the HorizontalLayout for a List?
When you touch scroll, it lets you scroll up and down. Whereas the vertical layout won't scroll horizontally.
Can anyone else confirm this?You'll need to set verticalScrollPolicy="auto" and horizontalScrollPolicy="on" styles on your List.
-
Good morning. When surfing(mainly in ebay) the listing information is listed vertically. How do I change it to horizontal?
I'm using an Apple supplied font (Hiragino Kaku Gothic Pro (Japanese Font)) as listed here (Cmd/Ctrl+F Hiragino). The Hiragino are the only fonts I've used so far and I remember TextEdit working like normal (As you've said yours has been working) a few days ago, but, like I said, now it's started to run pretty slow with vertical layout enabled.
EDIT: Well, I guess TextEdit hates spaces. I removed all the spaces (the only reason I was using spaces in the first place was because this is a speaking assignment and It's easier to seperate each segment), and it runs at normal speed once again. I guess I'll file a bug report for the spaces in TextEdit in vertical layout (And yes I tried spaces in Vertical with English too, still unbearably slow). What I noticed is that the performance slowdown builds up, it starts getting slow after the first space or two but then makes a dramatic differenc in speed as more spaces are added. Thanks everyone for the help. -
Make text box text start at top of box, not centered vertically
It seems all my text boxes i have start the text in the center of the box vertically, then spaces it out as you type more. is there a way to make it start at the top of the box and work down, just as if you were typing in Word or Notepad. if someone only types a few lines, it looks kinda odd having the text in the middle of the box with all that white space above and below it.
Hi,
You can set the vertical alignment of the caption and value (and both) for an object in the Paragraph tab - works just like Word.
Good luck,
Niall -
Turn horizontal layout to vertical when you place vertical photograph
Hi
I am Sathya Murthy
Basically I am photographer
I want to place photos in layers in a single psd file
for this i have found a scripting from the website
http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html
which is working fine.
But the problem is I have both vertical and horizantal photographs
I have marked certain place in my psd file which is in layers for horizantal photographs using rectangle tool
but suddenly when i want to insert vertical photos in horizantal layer the horizantal layer should change into vertical layer as photograph
for eg if i have rectangle layer which is 4 X 6 where 4 is length and 6 is width
and i have a vertical photo 6 X 4
the rectangle layer 4 X 6 should change 6 X 4 or in other words when it finds a vertical photo the rectangle layer marked for photo insertion
should change to vertical position.
I hope you understood
for this i need the scripting which should work fine with
InteractivePopulateCollage.jsx and
PopulateCollageTemplate.jsx
for the scripting files please visit this site where you can download
http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html
Please help me in this regard
Sathya Murthy
Thanks in AdvanceThe problem is you did not read the documentation. What is happening is your images are being fitted to the openings. You have created a template with a 3:2 landscale opening and your images is a 2:3 portrait. So the portrait is sized to fill the landscape opening. This will look like a center landscape crop of your portrait. Placing portraits into landscape and landscape into portrait openings will work however the composition will not be optiimal. You can use the move tool to change the composition in the final collage no croping has been done just masking.
Also this is not a perfect world many cameras have been produced that do not have an orintation sensor. So as far as Photoshop knows all image shot are Landscape portrait images will open on one side or the other and if you shoot with the camera inverted landscape image will open upside down. These script expect images files to be right side up when they a placed in. Photoshop is also not without bugs. I have seen some camera with orintation sensors where files will open in Photoshop right side up put when the ones that are protraits are placed into a document they are on side. There is code in the scripts that code around some bugs in different versions of Photoshop. They should work in CS2, CS3, CS4, and CS5. The only version of Photoshop scripting that didn't seem to have a scripting bug these scripts needed to code around is CS3.
Image File naming and placement order
Images are placed into collages from folders by the batching scripts in filename sort order. To allow you to control the order of image placement, you can prefix the Image Name you want stamped into the collage with a prefix sequence number followed by a "#" character. File Systems file name may be up to 255 characters in length and can not contain the special characters <>:"/\|?* So I could do something like this for file name (Sequence number,Collage Title,Image annotation#Image Name) in the future. You should also not expect a long name stamp to fit with the collage. As of now I just strip off everything up to and including the "#" before stamping the remaining part of the file name into the collage. This is also true in the interactive script. So right now you can use the prefix area anyway you want. However that may change in the future. The Collages templates themselves are populated in the order of the alpha channels "Image 1, Image 2, ..., Image "n" with the lower image number layers below higher number layers in the layers stack.
From the documentation More example
Note: Look at how Landscape images are fitted to Portrait cutouts and how Portrait Images are fitted to Landscape cutouts. For best results when you batch populate Photo Collage Templates Images and Cutout should have the same orientation.
Message was edited by: JJMack
Maybe you are looking for
-
I am having trouble downloading Itune, icloud etc onto my Windows 7 PC and keep getting the following error message "this installation pack could not be opened, verify that the package exists and that you can access it"
-
Is there a way to have multiple responders work on the same form?
I am creating a form that multiple people need to answer. For example, I work on a team where multiple people need to complete their part of the checklist for one employee. Is there a way multiple people can work on a specific for that was already s
-
How to keep songs on iphone, work computer and home computer the same?
How to keep songs on iphone, work computer and home computer the same? This seems like something everyone would want to do. I don't know why Apple won't give us a simple solution. They could even charge us for it. I would pay! Has anyone solved this?
-
Printing only one page problem
Hi, I have a printable class that needs to print some text only on 1 page. The thing is that when I hit print the printer prints 3 pages: page 1 - with correct content page 2 - empty page page 3 - page with content translated some how then the printi
-
Because the banks will not guarantuee internetbanking under Windows XP I have installed Windows 7 on two of my Pavilions. Because I am comfortable with XP and do not want a plethora of operating systems I have rolled my Pavilion t3710.nl back to XP (