How to resize JPanel at Runtime ??
Hi,
Our Project me t a problem as below, we hope to resize JPanel at Runtime , not at design time, ie, when we first click the button called "Move JPanel" , then we click the JPanel, then we can drag it around within main panel, but we hope to resize the size of this JPanel when we point to the border of this JPanel then drag its border to zoom in or zoom out this JPanel.
Please advice how to do that??
Thanks in advance.
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.event.*;
public class ResizeJPanels extends JPanel
protected JLabel label1, label2, label3, label4, labeltmp;
protected JLabel[] labels;
protected JPanel[] panels;
protected JPanel selectedJPanel;
protected JButton btn = new JButton("Move JPanel");
int cx, cy;
protected Vector order = new Vector();
public static void main(String[] args)
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new ResizeJPanels().GroupJLabels());
f.setSize(600,700);
f.setLocation(200,200);
f.setVisible(true);
private MouseListener ml = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
JPanel jp = new JPanel();
jp.setLayout(null);
Component[] c = ((JPanel)e.getSource()).getComponents();
System.out.println("c.length = " + c.length);
for(int j = 0; j < c.length; j++) {
if(c[j].getBounds().contains(p)) {
if(selectedJPanel != null && selectedJPanel != (JPanel)c[j])
selectedJPanel.setBorder(BorderFactory.createEtchedBorder());
selectedJPanel = (JPanel)c[j];
selectedJPanel.setBorder(BorderFactory.createLineBorder(Color.green));
break;
add(jp);
revalidate();
public JPanel GroupJLabels ()
setLayout(null);
addLabels();
label1.setBounds( 125, 150, 125, 25);
label2.setBounds(425, 150, 125, 25);
label3.setBounds( 125, 575, 125, 25);
label4.setBounds(425, 575, 125, 25);
//add(btn);
btn.setBounds(10, 5, 205, 25);
add(btn);
determineCenterOfComponents();
ComponentMover mover = new ComponentMover();
ActionListener lst = new ActionListener() {
public void actionPerformed(ActionEvent e) {
ComponentMover mover = new ComponentMover();
addMouseListener(mover);
addMouseMotionListener(mover);
btn.addActionListener(lst);
addMouseListener(ml);
return this;
public void paintComponent(final Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
Point[] p;
g2.setStroke(new BasicStroke(4f));
for(int i = 0 ; i < order.size()-1; i++) {
JPanel l1 = (JPanel)order.elementAt(i);
JPanel l2 = (JPanel)order.elementAt(i+1);
p = getCenterPoints(l1, l2);
g2.setColor(Color.black);
// g2.draw(new Line2D.Double(p[0], p[1]));
private Point[] getCenterPoints(Component c1, Component c2)
Point
p1 = new Point(),
p2 = new Point();
Rectangle
r1 = c1.getBounds(),
r2 = c2.getBounds();
p1.x = r1.x + r1.width/2;
p1.y = r1.y + r1.height/2;
p2.x = r2.x + r2.width/2;
p2.y = r2.y + r2.height/2;
return new Point[] {p1, p2};
private void determineCenterOfComponents()
int
xMin = Integer.MAX_VALUE,
yMin = Integer.MAX_VALUE,
xMax = 0,
yMax = 0;
for(int i = 0; i < labels.length; i++)
Rectangle r = labels.getBounds();
if(r.x < xMin)
xMin = r.x;
if(r.y < yMin)
yMin = r.y;
if(r.x + r.width > xMax)
xMax = r.x + r.width;
if(r.y + r.height > yMax)
yMax = r.y + r.height;
cx = xMin + (xMax - xMin)/2;
cy = yMin + (yMax - yMin)/2;
private class ComponentMover extends MouseInputAdapter
Point offsetP = new Point();
boolean dragging;
public void mousePressed(MouseEvent e)
Point p = e.getPoint();
for(int i = 0; i < panels.length; i++)
Rectangle r = panels[i].getBounds();
if(r.contains(p))
selectedJPanel = panels[i];
order.addElement(panels[i]);
offsetP.x = p.x - r.x;
offsetP.y = p.y - r.y;
dragging = true;
repaint(); //added
break;
public void mouseReleased(MouseEvent e)
dragging = false;
public void mouseDragged(MouseEvent e)
if(dragging)
Rectangle r = selectedJPanel.getBounds();
r.x = e.getX() - offsetP.x;
r.y = e.getY() - offsetP.y;
selectedJPanel.setBounds(r.x, r.y, r.width, r.height);
//determineCenterOfComponents();
repaint();
private void addLabels()
label1 = new JLabel("Label 1");
label2 = new JLabel("Label 2");
label3 = new JLabel("Label 3");
label4 = new JLabel("Label 4");
labels = new JLabel[] {
label1, label2, label3, label4
JLabel jl = new JLabel("This is resizeable JPanel at Runtime");
jl.setBackground(Color.green);
jl.setOpaque(true);
jl.setFont(new Font("Helvetica", Font.BOLD, 18));
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
panels = new JPanel[]{jp};
jp.setBorder(new LineBorder(Color.black, 3, false));
jp.setPreferredSize(new Dimension(400,200));
jp.add(jl, BorderLayout.NORTH);
for(int i = 0; i < labels.length; i++)
labels[i].setHorizontalAlignment(SwingConstants.CENTER);
labels[i].setBorder(BorderFactory.createEtchedBorder());
jp.add(labels[i], BorderLayout.CENTER);
jp.setBounds(100, 100, 400,200);
add(jp);
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.MouseInputAdapter;
public class Resizing extends JPanel {
public Resizing() {
super(null);
addPanel();
PanelControlAdapter control = new PanelControlAdapter(this);
addMouseListener(control);
addMouseMotionListener(control);
private void addPanel() {
JLabel jl = new JLabel("This is resizeable JPanel at Runtime");
jl.setBackground(Color.green);
jl.setOpaque(true);
jl.setFont(new Font("Helvetica", Font.BOLD, 18));
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
jp.setBorder(new LineBorder(Color.black, 3, false));
jp.add(jl, BorderLayout.NORTH);
jp.setBounds(50,50,400,200);
add(jp);
public static void main(String[] args) {
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new Resizing());
f.setSize(500,400);
f.setLocation(100,100);
f.setVisible(true);
class PanelControlAdapter extends MouseInputAdapter {
Resizing host;
Component selectedComponent;
LineBorder black;
LineBorder green;
Point offset = new Point();
Point start = new Point();
boolean dragging = false;
boolean resizing = false;
public PanelControlAdapter(Resizing r) {
host = r;
black = new LineBorder(Color.black, 3, false);
green = new LineBorder(Color.green, 3, false);
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
boolean hovering = false;
Component c = host.getComponent(0);
Rectangle r = c.getBounds();
if(r.contains(p)) {
hovering = true;
if(selectedComponent != c) {
if(selectedComponent != null) // reset
((JComponent)selectedComponent).setBorder(black);
selectedComponent = c;
((JComponent)selectedComponent).setBorder(green);
if(overBorder(p))
setCursor(p);
else if(selectedComponent.getCursor() != Cursor.getDefaultCursor())
selectedComponent.setCursor(Cursor.getDefaultCursor());
if(!hovering && selectedComponent != null) {
((JComponent)selectedComponent).setBorder(black);
selectedComponent = null;
private boolean overBorder(Point p) {
Rectangle r = selectedComponent.getBounds();
JComponent target = (JComponent)selectedComponent;
Insets insets = target.getBorder().getBorderInsets(target);
// Assume uniform border insets.
r.grow(-insets.left, -insets.top);
return !r.contains(p);
private void setCursor(Point p) {
JComponent target = (JComponent)selectedComponent;
AbstractBorder border = (AbstractBorder)target.getBorder();
Rectangle r = target.getBounds();
Rectangle ir = border.getInteriorRectangle(target, r.x, r.y, r.width, r.height);
int outcode = ir.outcode(p.x, p.y);
Cursor cursor;
switch(outcode) {
case Rectangle.OUT_TOP:
cursor = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
break;
case Rectangle.OUT_TOP + Rectangle.OUT_LEFT:
cursor = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
break;
case Rectangle.OUT_LEFT:
cursor = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
break;
case Rectangle.OUT_LEFT + Rectangle.OUT_BOTTOM:
cursor = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
break;
case Rectangle.OUT_BOTTOM:
cursor = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
break;
case Rectangle.OUT_BOTTOM + Rectangle.OUT_RIGHT:
cursor = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
break;
case Rectangle.OUT_RIGHT:
cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
break;
case Rectangle.OUT_RIGHT + Rectangle.OUT_TOP:
cursor = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
break;
default:
cursor = Cursor.getDefaultCursor();
selectedComponent.setCursor(cursor);
public void mousePressed(MouseEvent e) {
Point p = e.getPoint();
if(selectedComponent != null) {
Rectangle r = selectedComponent.getBounds();
if(selectedComponent.getCursor() == Cursor.getDefaultCursor()) {
offset.x = p.x - r.x;
offset.y = p.y - r.y;
dragging = true;
} else {
start = p;
resizing = true;
public void mouseReleased(MouseEvent e) {
dragging = false;
resizing = false;
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
if(dragging || resizing) {
Rectangle r = selectedComponent.getBounds();
if(dragging) {
r.x = p.x - offset.x;
r.y = p.y - offset.y;
selectedComponent.setLocation(r.x, r.y);
} else if(resizing) {
int type = selectedComponent.getCursor().getType();
switch(type) {
case Cursor.N_RESIZE_CURSOR:
r.height -= p.y - start.y;
r.y = p.y;
break;
case Cursor.NW_RESIZE_CURSOR:
r.width -= p.x - start.x;
r.x = p.x;
r.height -= p.y - start.y;
r.y = p.y;
break;
case Cursor.W_RESIZE_CURSOR:
r.width -= p.x - start.x;
r.x = p.x;
break;
case Cursor.SW_RESIZE_CURSOR:
r.width -= p.x - start.x;
r.x = p.x;
r.height += p.y - start.y;
break;
case Cursor.S_RESIZE_CURSOR:
r.height += p.y - start.y;
break;
case Cursor.SE_RESIZE_CURSOR:
r.width += p.x - start.x;
r.height += p.y - start.y;
break;
case Cursor.E_RESIZE_CURSOR:
r.width += p.x - start.x;
break;
case Cursor.NE_RESIZE_CURSOR:
r.width += p.x - start.x;
r.height -= p.y - start.y;
r.y = p.y;
break;
default:
System.out.println("Unexpected resize type: " + type);
selectedComponent.setBounds(r.x, r.y, r.width, r.height);
start = p;
}
Similar Messages
-
How to dynamically resize JPanel at runtime??
Hello Sir:
I met a problem, I need to resize a small JPanel called panel within a main Control JPanel (with null Layout) if I click the mouse then I can Drag and Resize this small JPanel Border to the size I need at runtime, I know I can use panel.setSize() or panel.setPreferredSize() methods at design time,
But I have no idea how to do it even I search this famous fourm,
How to dynamically resize JPanel at runtime??
Can any guru throw some light or good example??
ThanksWhy are you using a null layout? Wouldn't having a layout manager help you in this situation?
-
Hi guys any tips or advise on how to resize an image i know
there are various tools but is there a tool in Adobe flash
professional and how can I do it
cheersIn what way do you want to resize the image? Are you
importing graphics that you want to resize when you import them at
runtime? Do you want to resize the images to a specific size or
relative to one imported image? Or do you want to resize one or
more images for a specific purpose at runtime based on some user
input? Or is it something else? -
Resizing Swf at runtime based on content
Hi I am working on a project and I am trying to figure out how to resize the swf at runtime based on the content (which is brought in by xml) . What I am trying to do is similar to http://www.mustardlab.com/developer/flash/objectresize/ but unfortunately this is written in AS1 and doesnt help me much! If anyone could please explain to me how to do this in AS3 I would really appreciate it. I know I need to use the ExternalInterface but I am very new to AS3 and am not sure how to do this. I have searched and searched all over the internet and still can't figure it out. Any source code you might have would be AWESOME!
Thanks again,
KathyHi again:) I guess that’s the problem, I'm not sure of the code..i mean I guess I understand the basics..i need to call on the textField.height and send it to the javascript via the ExternalInterface..then I'm stuck..how to get the javascript to resize the div which is what I'm assuming it needs to do? Again, this I'm really new at this and I'm working on a site for a client..I have been struggling to get it to work..i'd dump the flash all together but she reallllllllllly wants it!
Here is the site if you want to see it. Its not finished yet but I'm getting there!
www.daedaldesigns.com/jackiegood/
Right now the issue is the text on some pages is short and on others is long..so I need to get it to expand.
Thanks again..I really appreciate your time!
Kathy -
Making a customable resizable JPanel, but it only works in certain L&F
Hi,
I have created the following resizable JPanel (so that I can set a minimum size it can be dragged to).
However, I need it to work under the system L&F, which is XP, but it wont work.
The code is below. if you run it the first time, and try to resize the dialog to a small value, you will see it shrinks in size, to a certain point.
then if you comment out the 2 lines i specified, and run it again, it wont. Anyone have any ideas? is this a known bug?
import javax.swing.*;
import java.awt.event.ComponentListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
public class ResizeTest extends JDialog {
public ResizeTest(JFrame owner) {
super(owner);
this.addComponentListener(resizeListener);
/* comment out the following 2 lines */
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
private ComponentListener resizeListener = new ComponentListener() {
public void componentHidden( ComponentEvent i_e ) { }
public void componentMoved( ComponentEvent i_e ) { }
public void componentResized( ComponentEvent i_e ) {
int width = ResizeTest.this.getWidth();
int height = ResizeTest.this.getHeight();
if( width < 50 ) { width = 50; }
if( height < 50 ) { height = 50; }
ResizeTest.this.setSize( width, height );
public void componentShown( ComponentEvent i_e ) { }
private static void test() {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton launchButton = new JButton("showDialog");
frame.setContentPane(launchButton);
final ResizeTest testDialog = new ResizeTest(frame);
testDialog.setMinimumSize(new Dimension(300, 300));
testDialog.setSize(500, 500);
testDialog.setPreferredSize(new Dimension(500, 500));
launchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
testDialog.pack();
testDialog.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
test();
}okay... I see what the problem is.
1) With those lines uncommented: The L&F is handling the window decorations. Because of this, it's basically a JWindow with custom painting and mouse handling. When you resize, it's constantly calling setSize, which constantly firing events, so your minimum sizing works as you expect.
2) With those lines commented: The OS is handling the window decorations. Because of this, there are 2 caveats:
a) There is a minimum width of the window of what looks like about 120-130 pixels. So you can't go any smaller then that for width. And for height, no smaller then the titlebar and lower border.
b) It only fires the component events when the mouse is released, cuz that's how the undelying native windows deal with it... or at least with Java.
For #1 above, there's still a minimum size for the L&F decorated windows. But this is related to what content is showing in the titlebar. Which in the case of the decorations showing, is smaller then what your were defining as a minimum.
So, basically, it's not a bug. It's just the way it is. It's always been like this. -
nice day,
during rezize JFrame simultaneously changing the size of JFrame Childs, how to stop, pause or wait for that and resize JFrame Childs just one time
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
public class PaintPanels extends JFrame {
private static final long serialVersionUID = 1L;
private final JPanel fatherPanel = new JPanel();
private SomePanel centerPanel;
private SomePanel northPanel;
private SomePanel southPanel;
public void makeUI() {
centerPanel = new SomePanel();
northPanel = new SomePanel();
southPanel = new SomePanel();
centerPanel.setName("centerPanel");
northPanel.setName("northPanel");
southPanel.setName("southPanel");
northPanel.setPreferredSize(new Dimension(1020, 170));
centerPanel.setPreferredSize(new Dimension(1020, 300));
southPanel.setPreferredSize(new Dimension(1020, 170));
fatherPanel.setLayout(new BorderLayout(5, 5));
fatherPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
fatherPanel.add(northPanel, BorderLayout.NORTH);
fatherPanel.add(centerPanel, BorderLayout.CENTER);
fatherPanel.add(southPanel, BorderLayout.SOUTH);
setLayout(new BorderLayout(5, 5));
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(fatherPanel, BorderLayout.CENTER);
pack();
setVisible(true);
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new PaintPanels().makeUI();
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class SomePanel extends JPanel {
private static final long serialVersionUID = 1L;
private GradientPanel titlePanel;
protected JLabel titleLabel;
int borderOffset = 2;
public SomePanel() {
setLayout(new BorderLayout(5,5));
setBorder(BorderFactory.createLineBorder(Color.gray, 1));
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
Component comp = e.getComponent();
String compName = comp.getName();
System.out.print("Mouse click from " + compName + "\n");
@Override
public void mousePressed(MouseEvent e) {
@Override
public void mouseReleased(MouseEvent e) {
@Override
public void mouseEntered(MouseEvent e) {
@Override
public void mouseExited(MouseEvent e) {
titleLabel = new JLabel(" Welcome World ", JLabel.LEADING);
titleLabel.setForeground(Color.darkGray);
titlePanel = new GradientPanel(Color.black);
titlePanel.setLayout(new BorderLayout());
titlePanel.add(titleLabel, BorderLayout.WEST);
titlePanel.setBorder(BorderFactory.createEmptyBorder(borderOffset, 4, borderOffset, 1));
titlePanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
titlePanel.setMinimumSize(new Dimension(300, 25));
titlePanel.setPreferredSize(new Dimension(800, 25));
titlePanel.setMaximumSize(new Dimension(1200, 25));
add(titlePanel, BorderLayout.NORTH);
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import javax.swing.JPanel;
class GradientPanel extends JPanel {
private static final long serialVersionUID = 1L;
public GradientPanel(Color background) {
setBackground(background);
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (isOpaque()) {// Color controlColor = UIManager.getColor("control");
//Color background = new Color(44, 61, 146);
//Color controlColor = new Color(168, 204, 241);
Color background = new Color(168, 210, 241);
Color controlColor = new Color(230, 240, 230);
int width = getWidth();
int height = getHeight();
Graphics2D g2 = (Graphics2D) g;
Paint oldPaint = g2.getPaint();
g2.setPaint(new GradientPaint(0, 0, background, width, 0, controlColor));
//g2.setPaint(new GradientPaint(0, 0, getBackground(), width, 0, controlColor));
g2.fillRect(0, 0, width, height);
g2.setPaint(oldPaint);
}nice day,
could you hepl me with some definitions, still I can't to define gap for first and last of JLabel (matrix), is there some hack for GridBagLayout,
hmmm, interesting that if I replace South JPanel and put there JPanet that contains only JButtons, then that's/just only this one (JPanel) doesn't any problems with synchronizations for repaint with JFrame,
result is: resize isn't smooth, Border jump, resize breaking,
already at a fraction of JComponents that I would like to display,
I certainly know that the reason is the LCD display, where its native resolution makes a huge problem with the edge of Border and FontSize, 'glass screen' doesn't suffering from similar diseases,
so there my question is how to stop the refresh, resize JPanels with its parents, therefore wait until the resize event ends on JFrame
import java.awt.*;
import javax.swing.*;
public class ChildPanel extends JPanel {
private static final long serialVersionUID = 1L;
public ChildPanel() {
JLabel hidelLabel;
JLabel firstLabel;
JTextField firstText;
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
for (int k = 0; k < 50; k++) {
hidelLabel = new JLabel(" ");
//hidelLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0.5;
gbc.weighty = 0.5;
gbc.gridx = k;
gbc.gridy = 0;
add(hidelLabel, gbc);
for (int k = 0; k < 5; k++) {
firstLabel = new JLabel("Testing Label : ", SwingConstants.RIGHT);
firstLabel.setFont(new Font("Serif", Font.BOLD, 20));
firstLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
gbc.fill = GridBagConstraints.HORIZONTAL;
//gbc.ipady = 0; //reset to default
//gbc.weighty = 1.0; //request any extra vertical space
//gbc.anchor = GridBagConstraints.PAGE_END; //bottom of space
gbc.insets = new Insets(0, 0, 5, 0); //top padding
gbc.gridx = 0; //aligned with JLabel 0
gbc.gridwidth = 8; //8 columns wide
gbc.gridy = k + 1;
add(firstLabel, gbc);
for (int k = 0; k < 5; k++) {
firstText = new JTextField("Testing TextField");
firstText.setFont(new Font("Serif", Font.BOLD, 20));
firstText.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 5, 0);
gbc.gridx = 9;
gbc.gridwidth = k + 8;
gbc.gridy = k + 1;
add(firstText, gbc);
for (int k = 0; k < 5; k++) {
firstLabel = new JLabel("Testing Label : ", SwingConstants.RIGHT);
firstLabel.setFont(new Font("Serif", Font.BOLD, 20));
firstLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 5, 0);
gbc.gridx = 20 + k;
gbc.gridwidth = 8;
gbc.gridy = k + 1;
add(firstLabel, gbc);
for (int k = 0; k < 5; k++) {
firstText = new JTextField("Testing TextField");
firstText.setFont(new Font("Serif", Font.BOLD, 20));
firstText.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 5, 0);
gbc.gridx = 29 + k;
gbc.gridwidth = 21 - k;
gbc.gridy = k + 1;
add(firstText, gbc);
import java.awt.*;
import javax.swing.JPanel;
class GradientPanel extends JPanel {
private static final long serialVersionUID = 1L;
public GradientPanel(Color background) {
setBackground(background);
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (isOpaque()) {
Color background = new Color(168, 210, 241);
Color controlColor = new Color(230, 240, 230);
int width = getWidth();
int height = getHeight();
Graphics2D g2 = (Graphics2D) g;
Paint oldPaint = g2.getPaint();
g2.setPaint(new GradientPaint(0, 0, background, width, 0, controlColor));
g2.fillRect(0, 0, width, height);
g2.setPaint(oldPaint);
} -
How to resize media's visual component resolution
Hello dear:
How to resize visual component resolution?
example:
I have a movie,this movie's resolution is 800*600dpi,I want this movie's visual component is 600*520.
Thankspublic Dimension getPreferredSize() {
int w = 0, h = 0;
if (vc != null) {
Dimension size = vc.getPreferredSize();
w = size.width;
h = size.height;
if (cc != null) {
Dimension size = cc.getPreferredSize();
if (w == 0)
w = size.width;
h += size.height;
if (w < 160)
w = 160;
return new Dimension(w, h);
these codes can't change movie's aspect ratio,eg one movie resolution is 600*500,I can't change this movie resolution to 400*400 on playing. The Transcode.java is chanage the movie file resolution, not my expect.
I wish the one movie resolution is 600*500,this movie full window in the JPanel that resolution is 400*400. -
I can't figure out how to resize my picture for my home or lock screens.
I can't figure out how to resize my picture for my home or lock screens. It shouldn't be his difficult. Any suggestions? I'm running the latest software. Thanks.
whichever app store you are connecting to, hyou need a credit card with an address in that country. Also, itunes gift cards must be in local currency too.
If you are in japan, you need to use the japan app store -
How to resize a jpg/gif file to a fix size using jimi ?
I have search from the web and didn't find any example on doing this.
Can any one give example on how to resize a jpg image. let say 120x240
to a fixed size 40x40 ?
thank youHi.
When you got that image in form of a file, just load it and invoke the image's getScaledInstance(...)-method.
Here's how it could work:
import java.awt.*;
public class Test {
public static void main(String[] argv) {
// define where the image comes from:
URL toImage = new URL("file:/C:/test.jpg"); // or the like
// get the image:
Image image = Toolkit.getDefaultToolkit().createImage(toImage);
// scale the image to target size (40x40 here):
Image smallImage = image.getScaledInstance(40, 40, Image.SCALE_DEFAULT);
// you might want to do other things like displaying it afterwards
}HTH & cheers,
kelysar -
How to resize a table in Pages 5?
How to resize a table in Pages 5? It can be resized vertically but not horizontally.
stuart13 wrote:
How to resize a table in Pages 5? It can be resized vertically but not horizontally.
The controls are in the Format panel, Arrange Tab.
Jerry -
How to resize a photo from CameraUI?
Hi there,
i really need som help here. I cant seem understand how to resize an still image taken with the camera. Here are the code so far(also with the upload part). I just need a thumbnail to be uploaded to the server, not the HQ-image. Any ideas?
Simple AIR for iOS Package for selecting a cameraroll photo or taking a photo and processing it.
Copyright 2012 FIZIX Digital Agency
http://www.fizixstudios.com
For more information see the tutorial at:
http://www.fizixstudios.com/labs/do/view/id/air-ios-camera-and-uploading-photos
Notes:
This is a barebones script and is as generic as possible. The upload process is very basic,
the tutorial linked above gives information on how to post the image along with data to
your PHP script.
The PHP script will collect as $_FILES['Filedata'];
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.media.Camera;
import flash.media.CameraUI;
import flash.media.CameraRoll;
import flash.media.MediaPromise;
import flash.media.MediaType;
import flash.events.MediaEvent;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.utils.IDataInput;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.utils.ByteArray;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.errors.EOFError;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
// Define properties
var cameraRoll:CameraRoll = new CameraRoll(); // For Camera Roll
var cameraUI:CameraUI = new CameraUI(); // For Taking a Photo
var dataSource:IDataInput; // Data Source
var tempDir; // Our temporary directory
CameraTest() ;
function CameraTest()
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
// Start the home screen
startHomeScreen();
// =================================================================================
// startHomeScreen
// =================================================================================
function startHomeScreen()
trace("Main Screen Initialized");
// Add main screen event listeners
if(Multitouch.supportsGestureEvents)
mainScreen.startCamera.addEventListener(TouchEvent.TOUCH_TAP, initCamera);
mainScreen.startCameraRoll.addEventListener(TouchEvent.TOUCH_TAP, initCameraRoll);
else
mainScreen.startCamera.addEventListener(MouseEvent.CLICK, initCamera);
mainScreen.startCameraRoll.addEventListener(MouseEvent.CLICK, initCameraRoll);
// =================================================================================
// initCamera
// =================================================================================
function initCamera(evt:Event):void
trace("Starting Camera");
if( CameraUI.isSupported )
cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected);
cameraUI.addEventListener(Event.CANCEL, browseCancelled);
cameraUI.addEventListener(ErrorEvent.ERROR, mediaError);
cameraUI.launch(MediaType.IMAGE);
else
mainScreen.feedbackText.text = "This device does not support Camera functions.";
// =================================================================================
// initCameraRoll
// =================================================================================
function initCameraRoll(evt:Event):void
trace("Opening Camera Roll");
if(CameraRoll.supportsBrowseForImage)
mainScreen.feedbackText.text = "Opening Camera Roll.";
// Add event listeners for camera roll events
cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected);
cameraRoll.addEventListener(Event.CANCEL, browseCancelled);
cameraRoll.addEventListener(ErrorEvent.ERROR, mediaError);
// Open up the camera roll
cameraRoll.browseForImage();
else
mainScreen.feedbackText.text = "This device does not support CameraRoll functions.";
// =================================================================================
// imageSelected
// =================================================================================
function imageSelected(evt:MediaEvent):void
mainScreen.feedbackText.text = "Image Selected";
// Create a new imagePromise
var imagePromise:MediaPromise = evt.data;
// Open our data source
dataSource = imagePromise.open();
if(imagePromise.isAsync )
mainScreen.feedbackText.text += "Asynchronous Mode Media Promise.";
var eventSource:IEventDispatcher = dataSource as IEventDispatcher;
eventSource.addEventListener( Event.COMPLETE, onMediaLoaded );
else
mainScreen.feedbackText.text += "Synchronous Mode Media Promise.";
readMediaData();
// =================================================================================
// browseCancelled
// =================================================================================
function browseCancelled(event:Event):void
mainScreen.feedbackText.text = "Browse CameraRoll Cancelled";
// =================================================================================
// mediaError
// =================================================================================
function mediaError(event:Event):void
mainScreen.feedbackText.text = "There was an error";
// =================================================================================
// onMediaLoaded
// =================================================================================
function onMediaLoaded( event:Event ):void
mainScreen.feedbackText.text += "Image Loaded.";
readMediaData();
// =================================================================================
// readMediaData
// =================================================================================
function readMediaData():void
mainScreen.feedbackText.text += "Reading Image Data.";
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes( imageBytes );
tempDir = File.createTempDirectory();
// Set the userURL
var serverURL:String = "http://www.hidden_in_this_example.com/upload.php";
// Get the date and create an image name
var now:Date = new Date();
var filename:String = "IMG" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds;
// Create the temp file
var temp:File = tempDir.resolvePath(filename);
// Create a new FileStream
var stream:FileStream = new FileStream();
stream.open(temp, FileMode.WRITE);
stream.writeBytes(imageBytes);
stream.close();
// Add event listeners for progress
temp.addEventListener(Event.COMPLETE, uploadComplete);
temp.addEventListener(IOErrorEvent.IO_ERROR, ioError);
// Try to upload the file
try
mainScreen.feedbackText.text += "Uploading File";
//temp.upload(new URLRequest(serverURL), "Filedata");
// We need to use URLVariables
var params:URLVariables = new URLVariables();
// Set the parameters that we will be posting alongside the image
params.userid = "1234567";
// Create a new URLRequest
var request:URLRequest = new URLRequest(serverURL);
// Set the request method to POST (as opposed to GET)
request.method = URLRequestMethod.POST;
// Put our parameters into request.data
request.data = params;
// Perform the upload
temp.upload(request, "Filedata");
catch( e:Error )
trace(e);
mainScreen.feedbackText.text += "Error Uploading File: " + e;
removeTempDir();
// =================================================================================
// removeTempDir
// =================================================================================
function removeTempDir():void
tempDir.deleteDirectory(true);
tempDir = null;
// ==================================================================================
// uploadComplete()
// ==================================================================================
function uploadComplete(event:Event):void
mainScreen.feedbackText.text += "Upload Complete";
// ==================================================================================
// ioError()
// ==================================================================================
function ioError(event:Event):void
mainScreen.feedbackText.text += "Unable to process photo";1. Create a BitmapData of the correct size of the full image
2. Use BitmapData.setPixels to create pixel data from your byteArray
3. Make a new Bitmap, Bitmap.bitmapData = BitmapData
4. Create a matrix with the correct scaling factors for your thumbnail
5. Create a new BitmapData the size of your thumb
6. Use BitmapData.draw to draw your image data from the Bitmap to the new BitmapData with the scaling matrix
7. Use BitmapData.getPixels to create a bytearray from your thumb BitmapData
8. save it
You'll have to look up the AS3 reference to see how all these methods work. -
How can I fix the Runtime Error R6034 so that I can correctly install iTunes on my PC ? I get a notice that states ' An application has made an attempt to load the C runtime library incorrectly - Please contact the application's support team for more info
Hey Debbiered1,
Follow the steps in this link to resolve the issue:
iTunes 11.1.4 for Windows: Unable to install or open
http://support.apple.com/kb/TS5376
When you uninstall, the items you uninstall and the order in which you do so are particularly important:
Use the Control Panel to uninstall iTunes and related software components in the following order and then restart your computer:
iTunes
Apple Software Update
Apple Mobile Device Support
Bonjour
Apple Application Support (iTunes 9 or later)
Important: Uninstalling these components in a different order, or only uninstalling some of these components may have unintended affects.
Let us know if following that article and uninstalling those components in that order helped the situation.
Welcome to Apple Support Communities!
Take care,
Delgadoh -
How to display BITMAP at runtime
Hey all....
I am new to Photoshop SDK CS2 plugin programming. Can anyone help me to find out any code or any information to display bitmap image on plugin dialog using photoshop API and not the Windows API or MFC. I am just using a simple Dialog extending PIDialog Class and placed a picture control at design time using resource editor in windows (Visual Studio).
When I pass the resourceID of an Image in design time to picture control it displays the image and plugin is also working good but don't know how to pass it at runtime.
thanksHi,
Thanks for your reply. My Plugin is an Automation type plugin and is visible in File/Automate menu. I am just opening a 'File Browse Dialog Box' through 'Open File' Button on Plugin Dialog to select a image file (*.bmp) then I want to display that image in thumbnail in Picture Control box on plugin Dialog (just like the File/Automate/Picture Package... plugin already included in Photoshop cs2).
I have also downloaded the code given by you. again thanks for that. I am trying to understand the code. But I think it is too much for just displaying an image in picture control.
Thanks -
How to resize my monitor resolution in OS X 10.5.8
Hello I have a question I am new to mac and I was trying to resize my desktop resolution. I'm using a 720i TV utilizing the HDMI and using the convertor to make it DVI and for some reason when I use the 720 resolution its all off center and it won't let me resize it like it does in Windows but it works when i have it at 1280 x 960 problem is I don't want that resolution it doesn't look as good on my TV. I have tried everything and can't find any software that will allow me to do this. And I use the same monitor for my Windows machine and it works perfect PLEASE HELP
Yeah..... I know that I want to know how to resize a resolution the 1280 x 720 doesn't show up right it's making everything go off the sides so I can't see everything on my desktop in windows my nvidia control panel would allow me to resize my monitor to fit any resolution i want to know how to do that on a mac
-
How to resize all pages -Acrobat 9 Pro Extended ? ?
I came across a pre-existing pdf file of an old book of genealogy. According to the front pages, it was 'Digitized by Microsoft', so I know nothing on how it was generated. Total pages are in excess of 1,100.
In viewing the pages, they are reflected as 2 pages to a view; not the book opened with the spine in the middle, but images side by side ... in numerical order ... and they appear as a normal sized 2 page for that view. When I print out a page, by number, it also prints out in a normal size on an 8x11 inch sheet of paper.
However, rather than print page by page on individual sheets of paper, I want to print out multiple pages, 2 to a sheet of paper. In doing this, the images of the pages come up as 3x5 inch; thus not readable if printed without the usage of magnifier.
Not that familiar with the program, but tried to do a resize process by setting some adjustments and then to a new pdf file. It did not change that much ... and increased the file size dramatically.
I am a novice to these processes. Can someone advise how to resize the whole file, with images of pages side by side, so that when multiple print is used for 2 pages the size comes up closer to something like 5x7 inch each?
ThanksLet me try it this way.....
1. The pdf file, when initially opened up, in the opening view shows 2 simotaneous pages side by side ... with hardly a divider between them. This at this point has nothing to do with the print mode.
2. The book in question was 'Digitized by Microsoft' ... don't know if that makes any difference, but thought it would help to under stand that it was not created by the normal Adobe Acrobat method.
3. Now, when I go to the Print mode, from where I just viewed the 2-side-by-side pages, the initial view there, for 'page', is just 1 page ... not the 2 page view I just came from ... and it will print out this view in a full sheet version.
4. But, not wanting to print out 1130 pages, want to print multi-page as allowed under Acrobat options.
5. So choose multi-page and 2 pages and "Print to printable area"..
6. When this option appears in the print viewing window, the 'images' (presuming that to be the correct reference) are small, over the normal (roughly) 5 x 7 inch (each) for a 2-page print option.
7. With the 2-page print option, the images are only 3.5 x 5.25 inches ... rather than something like 5 x 7 inch ... which is difficult to read without a magnifier. [Note: This 3.5 x 5.25 is as indicated in Properties that the original 'Digitizing' did.
8. So, in essence, how can one change the default individual image size from 3.5 x 5.25 inch size, to something closer to 5 x 7 inch size ... so that each image fills in more of it's half of the 8.5 x 11 inch page being printed ... rather than the small size reflected in the attached jpg ?
I've attached a jpg of the print screen, and one of the 2 page side-by-side 'default' view in Acrobat.
Thanks
Maybe you are looking for
-
Wanted conversion of character from uppercase to lowercase.
Hi all, I am useing one function to conver amount numbers to character conversion. but they r comming in upper case. but i want in lower case. and also i want to remove "rupees " word at the end of the wording. for example. Rs.123 /- output is: ONE H
-
Hi guru. Can it is possible create an help in POV for a listbox field on WEB ABAP Dynpro? If it is possible, can I realize it? Regards Angela
-
Get element in combo box indicator
a vi generates an array of strings, how can I select one element with a combo box and send it to another vi as if it is a control? thanks
-
Hi All, Is the option to see the process form values for a resource object provisioned to an user not available in OIM11g R2 ? If so , how can we see the process form values for each Application instance provisioned to an user ? Thanks in Advance.
-
Activation not available for PS CS
Hi, I am still running PS CS on Wondows 7 - it does all that I need. I just cloned my system disk to a SSD and had to make some changes to the virtual memory settings as a result. PS CS now says that the machine configuration has changed and it nee