Resizing component in JScrollPane
Hi!
I want to do the following: when the button pressed, resize the component(JPanel) inside the JScrollPane.
I tried the following code:
jPanel1.setPreferredSize(new Dimension(400, 300));
jScrollPane1.getViewport().add(jPanel1, null);
void jButton1_actionPerformed(ActionEvent e)
jPanel1.setPreferredSize(new Dimension(4000, 3000));
When I press the button, nothing happens.
Please help.
Thank you, Stas, but it didn't work. Now my code is:
void jButton1_actionPerformed(ActionEvent e)
jPanel1.setPreferredSize(new Dimension(4000, 3000));
((Component)jScrollPane1).invalidate();
jScrollPane1.validate();
jScrollPane1.repaint();
I expected my horizontal and vertical bars to change ( the sign that the panel's size changed), but they didn't.
Similar Messages
-
Hi there,
I'm working on a component, which is different as I've done
in the past. On off possible properties that can be modified is an
image background, which would be used as preview in the Live View,
when the component is placed to the Stage, during development. OK,
this isn't complicated. The issue is that any background image has
different dimension. I need to resize the component on the Stage,
when the user changes the background image. Is it possible from the
component actionscript code to resize the component instance on the
Stage? When I try to change the size via the setSize method, the
component is resized, but this change isn't visible during
development in the Flash IDE. I have to manually resize the
component on the Stage to see, how the result will look, or I can
publish and preview the compiled SWF.
Does anybody have some solution for this issue?
Thank you,
MichalThis is my code :
public class ResizeComponent extends javax.swing.JFrame {
public ResizeComponent() {
initComponents();
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
lbImage = new javax.swing.JLabel();
lbText = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Resize Component");
jPanel1.setLayout(null);
jPanel1.setBackground(new java.awt.Color(0, 0, 0));
lbImage.setIcon(new javax.swing.ImageIcon("C:\\Users\\admin\\Desktop\\117.jpg"));
jPanel1.add(lbImage);
lbImage.setBounds(10, 10, 200, 300);
lbText.setFont(new java.awt.Font("Tahoma", 1, 34));
lbText.setForeground(new java.awt.Color(0, 0, 204));
lbText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbText.setText("Dian Sastro");
jPanel1.add(lbText);
lbText.setBounds(10, 320, 200, 30);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-227)/2, (screenSize.height-385)/2, 227, 385);
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ResizeComponent().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lbImage;
private javax.swing.JLabel lbText;
// End of variables declaration
Can you help me? -
Getting Component from JScrollPane
OK, I think that there must be a way to get the component that is inside of my JScrollPane, but I do not see that method in the Java API specifications. I have the following:
//Set the ViewportView to the component ExamplePanel
JScrollPane scrollpane = new JScrollPane(new ExamplePanel()); //ExamplePanel extends JPanel
//Now I want to get ExamplePanel
The only thing I found in JScrollPane that returns a component is getCorner that takes a string key or something. I just want my component ExamplePanel(). please help.
Thanks in advance.component1 = ((JInternalFrame).getContentPane().getComponent(0);
//component1 = JScrollPane
component2 = ((JScrollPane)component1).getComponent(0);
//component2 = JViewport
component3 = ((JViewport)component2).getComponent(0);
//component3 = COMPONENT INCIDE THE jscrollpane -
Hi,
I have a frame containing a JTable and a panel with buttons. When the window gets resized, I would like that the jtable takes the extra space and that the button panel stays the same. How can I do that? The jtable panel is already the "Center" and both panels stay the same...
Thanks,
Marie
Here's the code:
package test;
import javax.swing.*;
import java.awt.AWTEvent;
import java.awt.event.WindowEvent;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
public class Testframe extends JFrame {
private JPanel mainPanel = new JPanel();
private JPanel buttonPanel = new JPanel();
private JPanel tablePanel = new JPanel();
//Button panel
private JButton applyTableBt = new JButton("Generate Table");
private JButton addBt = new JButton("Add");
private JButton editBt = new JButton("Edit");
private JButton deleteBt = new JButton("Delete");
private JButton matchBt = new JButton("Find");
private JButton saveBt = new JButton("Save to file");
private JButton loadBt = new JButton("Load from file");
* Constructor.
* @param a_parent Frame
protected Testframe() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
this.setResizable(true);
this.setVisible(true);
pack();
} catch (Exception e) {
e.printStackTrace();
* Initialization of the dialog.
* @throws Exception
private void jbInit() throws Exception {
this.setTitle("Pattern management - CAT");
Object[][] data = { {"11", "12", "13", "14", "15", "16", "17", "18"},
{"21", "22", "23", "24", "25", "26", "27", "28"}
Object[] names = {"col1", "col2", "col3", "col4", "col5", "col6",
"col7", "col8"};
JTable table = new JTable(data, names);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//table.setColu
TableColumnModel colModel = table.getColumnModel();
for (int i = 0; i < table.getColumnCount(); i++) {
TableColumn column = colModel.getColumn(i);
column.setPreferredWidth(511);
JScrollPane scrollPane = new JScrollPane(table);
tablePanel.add(scrollPane);
//Layout = vertical box with vertical gap
buttonPanel.setLayout(new GridLayout(7, 1, 0, 5));
buttonPanel.add(applyTableBt);
buttonPanel.add(addBt);
buttonPanel.add(editBt);
buttonPanel.add(deleteBt);
buttonPanel.add(matchBt);
buttonPanel.add(saveBt);
buttonPanel.add(loadBt);
//mainPanel.setLayout(new BorderLayout());
mainPanel.add(tablePanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.EAST);
this.setContentPane(mainPanel);
* Overrides this class to call the good method when the dialog is closed.
* @param a_windowE WindowEvent
protected void processWindowEvent(WindowEvent a_windowE) {
//If it is a request to close the window (X)
if (a_windowE.getID() == WindowEvent.WINDOW_CLOSING) {
cancel();
super.processWindowEvent(a_windowE);
* Closes the dialog.
private void cancel() {
dispose();
private static void createAndDisplayFrame() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
new Testframe();
public static void main(String[] args) {
createAndDisplayFrame();
}try changing these lines
mainPanel.add(tablePanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.EAST);
this.setContentPane(mainPanel);
to this
mainPanel.add(buttonPanel, BorderLayout.EAST);
getContentPane().add(scrollPane, BorderLayout.CENTER);
getContentPane().add(mainPanel, BorderLayout.EAST); -
How to resize component dynamically?
I customized a LCD component extended from JLabel. It has two type of dimension, i.e.
8x8 and 16x16. When clicking 16x16 button, LCD component should be resized to be 16x16
by calling setModelSize method. But it doesn't work.
Please tell me the answer, thank you!
public void setModelSize(int xCells, int yCells) {
this.xCells = xCells;
this.yCells = yCells;
repaint();
}it also depends on the layout of the container. if the layout is null, then u can easily adjust the size. of course then u have to initialize the position and size of the components first in order to see them.
-
Heavyweight component in JScrollPane... any solution?
Hi all,
I have a fairly large application that, among other things, has a central, scrollable pane where the program's main content is displayed. The GUI is all written in swing.
Now I'm starting to display third-party applications within my program, and the main window of their applications is occasionally a heavy-weight AWT panel. When I try to add these to my JScrollPane, I get the predictable result that the AWT component is always on top, and so appears to overlap the borders of the scrollpane.
I know the solution read everywhere is "Don't put heavy-weight components in JScrollPanes" and "change your JScrollPane to a ScrollPane," but this would really wreck things, as the entire gui is relying on the various elements being jcomponents.
So, I know the easiest answer is "rewite your code so you can use an AWT ScrollBar," but does anyone have any clever solution -- even faking an overlap in some way, I don't know -- that might allow me to use a heavyweight component in my JScrollBar and not have it overlap?
Thanks a million,
TimIf you want to paint your menu over the heavy component, you have to call setDefaultLightWeightPopupEnabled(boolean) with a false value. But I didn't understand why the AWT component is painted over the JScrollPane container. I have written code with heavy and lightweighted components, but it behave correctly in my case. without sp�cial code for that.
-
Dynamically resizing Knobs on JScrollPane when JPanel contents grows
If I dynamically add components to a JPanel (causing it to grow in length e.g. Flowlayout) that is inside a JScrollPane how can I detect and adjust the JScrollPane knobs so that they show the complete JPanel.
I know that if I set the JPanel's preferred size it will do this, but how do I know what this size is? I don't want to have to track the size of the components I am adding to the JPanel and work it all out manually, there must be an easier way to do it.I know that if I set the JPanel's preferred size it will do this
there must be an easier way to do it. You should NOT be manually setting the preferred size, just let the layout manager calculate it.
After adding components to the panel you just invoke:
panel.revalidate(); -
How to override components when resize component
I tested this code which resize tab pane when the tab is double clicked.
final Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
tabPane.setOnMouseClicked(new EventHandler<MouseEvent>()
private double sizeX, sizeY;
private boolean first = true;
@Override
public void handle(MouseEvent me)
if (first)
sizeX = mainPane.getWidth();
sizeY = mainPane.getHeight();
first = false;
if (me.getButton().equals(MouseButton.PRIMARY) && me.getClickCount() % 2 == 0)
if (sizeX != mainPane.getWidth() || sizeY != mainPane.getHeight())
mainPane.setPrefSize(sizeX, sizeY);
else
mainPane.setPrefSize(primaryScreenBounds.getWidth(), primaryScreenBounds.getHeight());
I want the affected panel to take precedence over all other panels. For example make the panel to overlay all other panels or maybe to hide all other panels.I tested this code which resize tab pane when the tab is double clicked.
final Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
tabPane.setOnMouseClicked(new EventHandler<MouseEvent>()
private double sizeX, sizeY;
private boolean first = true;
@Override
public void handle(MouseEvent me)
if (first)
sizeX = mainPane.getWidth();
sizeY = mainPane.getHeight();
first = false;
if (me.getButton().equals(MouseButton.PRIMARY) && me.getClickCount() % 2 == 0)
if (sizeX != mainPane.getWidth() || sizeY != mainPane.getHeight())
mainPane.setPrefSize(sizeX, sizeY);
else
mainPane.setPrefSize(primaryScreenBounds.getWidth(), primaryScreenBounds.getHeight());
I want the affected panel to take precedence over all other panels. For example make the panel to overlay all other panels or maybe to hide all other panels. -
Using Resize effect to resize the component to 100percent
Hi all,
I am using resize component to show the opening of a datagrid which contains itemrenderers.The number of itemrenderers is not fixed hence i want to use the resize effect to resize the grid from height=0 to height=100%. I m not getting any clue as to how to do percent resize with effects.
Please share ur ideas.Thanks for your answer!
I tried setting the font size to Auto, but the problem is that the text starts off really small, at about 12pt font. I really need it to start with large text, eg to start off as one word at say 60pt size, and be able to go down to two words on the top line and two words on the bottom line, at around 20 pt size. So it starts large, but goes down in size with the more text that is put in.
I am making editable Avery Labels for teachers - 10 to a page - to put kids names in, or subjects and names.
Also... is it possible to cenre the text vertically with in the text box?
Thanks very much for your advice! -
I'm trying to add a Canvas to a JScrollPane, but it always seems to show the ENTIRE canvas instead of just a scrollable portion of it.
I've read about and tried examples using methods such as 'setPreferredSize' for both the scroll pane and it's container (I'm using a JPanel), but neither of these seem to stop the canvas from showing at full size.
I've also tried 'scrollPane.setViewportView(myCanvas)', but this doesn't work either.
Any ideas anyone?? I'm really stuck on this.Canvas is a heavy component and JScrollPane is a light component. A heavy component always paint on top a light component.
The better is using only Swing's components or only AWT's components. Mixing have some problems
Hope this help. -
Trouble Scrolling down(JTextPane inside JScrollPane)
I am writting a java interface to the Jabber IM system. I'm trying to allow html in the messages, so I have a JTextPane that I use to show what has been said. In order to scroll, I've placed the JTextPane within a JScrollPane. When a new message needs to be placed into the JTextPane, I set the JTextPane to the proper text and set the scroll bar from the scroll pane to it's .getMaximum() value. My problem is that the .getMaximum() function only gets the NEW, ACTUAL maximum AFTER the JTextPane has been parsed and painted into the JPanel. The time it takes to do this is proportional to the length of the text within the JText pane and relative to the speed of the computer. So, the scroll bars should be done in response to the completion of the painting of the JTextPane instead of a set time delay. I don't know how to do this. I assume I need to overwrite some paint or repaint function, but I don't know which one to overwrite. The JTextPane is in a JScrollPane in a JSplitPane in a JPanel in a JFrame, if that helps at all.
I've been stuck on this forever..
Thanks for any help.Gave you 6 $. JTextPane doesn't have the insert function, so I've been using setText(). The problem is that the second the Pane is redrawn, it shows the top of the document, then scrolls to the bottom. This takes a fraction of a second, but still is undesireable.
What I'm trying to do is make a new textpane object, set the text, set the caret position, THEN replace the old pane. The problem is, I can't just use oldPane = newPane because that just makes oldPane reference the new Object.(The object shown is then only referenced from the parent swing component, a JScrollPane) I've tried using the .setViewportView on the JScrollPane that the JTextPane is within, but then it doesn't scroll to the caret position.
I've gotten it to work once. I had created all new objects(JTextPane within JScrollPane within JSplitPane within JPanel) adding each to it's parent and adding the JPanel to the container. This worked ONCE! I changed the code, then changed it back and it didn't work again...
Here's the code I have for buffering the JTextPane.
if(chatPane == chatPaneBuffer2){
chatPaneBuffer1.setText(chatStringBuffer.toString());
chatPaneBuffer1.setCaretPosition(chatPaneBuffer1.getDocument().getLength());
chatPane = chatPaneBuffer1;
}else{
chatPaneBuffer2.setText(chatStringBuffer.toString());
chatPaneBuffer2.setCaretPosition(chatPaneBuffer2.getDocument().getLength());
chatPane = chatPaneBuffer2;
This works, but somehow I need the object chatPane is pointing at to be referenced by my JScrollPane. -
There seems to be very little information on developing a
custom component with live preview.
So far i've created a swf whose application class extends
UIComponent.
I've also created a custom component.
Then I've added the Live Preview field in the custom
component's Component Definition.
What I would like to do now is reposition elements within the
preview swf when the user resizes the component.
To do this i need to know two things - 1 what event to listen
for when the user resizes the component, and 2 the current
dimensions of the resized component.
1. My only success was that ComponentEvent.SHOW seems to
dispatch when the user resizes the component. (i had no luck with
any of the RESIZE events - Event.RESIZE etc)
2. However the width/height properties don't seem to change
on resize, they stay at the original dimensions of the component.
Any ideas?Hey Craig :)
now I'm not certain about this under 3, but when developing
with under 2 with a live preview one needs to include a 'magical'
MC named 'xch' (instance name as well) that basically contains
'nothing' - it's a empty mc on the preview files timeline. there
are 'other' things as well however, in the live preview file one
must create a method named 'onUpdate' and assign a property of the
xch named 'instance' to 'this' (ref the timeline of the preview
file... previous to the method declaration) then within the
onUpdate method 'all' properties of the component and statements
within the method refer to xch.prop = blah blah, xch.otherprop =
blah blah
it's quite complicated and doesn't really make a lot of
sense, but that seems to be the way in which the working file
relates to the live preview file - ie. 'through' the xch clip which
triggers the onUpdate method
from what i remember, it's this mc that 'helps' the resize
event 'make' the connection between the event and the preview file,
seems to me that there was something else involved as well but i
cant seem to remember atm - I found this information in an article
on building components, however the page is no longer valid and i
couldn't track it down for you (it was a good tut too) sorry wish i
had more info for you. -
Hello,
I feel I'm going mad with Swing.
I have a main main JTabbedPane: main.
First component: JEditorPane : source
Second Component: JPanel : view( = new JPanel())
In view I have:
JPanel toolbox to NORTH and JSplitPane: ds to CENTER.
In ds I have:
Left component: new JScrollPane(design) where design=new JPanel()
Right component: JSplitPane(....) : called pe
First problem:
In ds the left component is too small. I tried to use all functions available , no result. I want the right component(pe) to have width=200, but no chance. It is too big. Why?
Second problem:
The scrolls are not appearing on the left at the ds(JSplitPane)
Third problem:
I add different components to design JPanel(the one which is placed into a JScrollPane which is related to the second problem) but nothing happens. They won't appear on design which is the same and without no scrolls.
Please help me solve this Swing mistery.
Thank you all.The split pane, by default, will size its two halves based on their preferred sizes. If the combined preferred sizes are too small (for the size of the spilt pane) then the extra space is distributed based on JSplitPane's resize weight. The default is to add the extra to the right hand side, see JSplitPane.setResizeWeight for an explanation. If you really want the right hand side to be exactly 200 pixels then you can programmatically move the divider to a location that would leave the right hand side to be 200. Or you can set the preferred size of the component you place there to 200 and set a resize weight that will give the extra space to the left instead of the right.
I am not sure about why the scroll bars are not showing up. Does it need scroll bars?
May I suggest creating a simple demo app to show the problem? Often I solve my own problems doing this otherwise you have some code for us to look at and play with.
Ian -
Negative Ranges, Java Scrollbars and Java2D.
Hiya all. I have a bit of an odd problem. Im working on graph animation. Graphs tend to be laid out with an initial random seed which tends to give a good smattering of negative values as well as postive ones. Now, I tend to shift all the nodes by a certain amount so that all are visible. However, once the user starts playing with the graph, there is no guarantee that all the values will still be positive. This means another shift is required which means a lot of jerky screen movements which is the last thing we need.
I was wondering. If i create a JPanel of say, size 1000 x 1000 and perform one Java2D affine translate of 500 by 500, that should center my graph on the JPanel. If i place this JPanel within a JScrollPane can I then set the scrollbars to appear halfway along their tracks, i.e, have the viewport lined up on center 500 by 500?
If anyone else has had a problem like this, i'd be most obliged if someone could post it here. Actually, probably the best thing would be some kind of canvas grow function such as the one in photoshop. When the canvas needs resizing, you can resize in one of 4 directions cant you? Yet the view remains constant. I imagine something like this isnt easy.then you may recalculate the bounds and adjust the
scrollbars consquenlty? for example, minimum -7,
maximum 10 then set the scrolbar to have a maximum of
17, etc. and you can always modify the scrollbars to
have a right size so the user can scroll the graphsHuh? Here's a demo where the component just resizes in a JScrollPane:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SampleComponent extends JPanel{
private int minX=-100, maxX=100, minY=-100, maxY=100;
public Dimension getPreferredSize() {
return new Dimension(maxX-minX, maxY-minY);
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
g2.translate(-minX, -minY);
g2.drawLine(minX, 0, maxX, 0); //x axis
g2.drawLine(0, minY, 0, maxY); //y axis
g2.dispose();
public void rescale(float scale) {
minX=(int)(scale*minX);
maxX=(int)(scale*maxX);
minY=(int)(scale*minY);
maxY=(int)(scale*maxY);
invalidate();
revalidate();
repaint();
public static void main(String[] args) {
final SampleComponent app = new SampleComponent();
JScrollPane sp = new JScrollPane(app);
JPanel south = new JPanel();
JButton zoomIn = new JButton("zoom in");
south.add(zoomIn);
zoomIn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
app.rescale(1.5f);
JButton zoomOut = new JButton("zoom out");
south.add(zoomOut);
zoomOut.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
app.rescale(.75f);
final JFrame f = new JFrame("SampleComponent");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(sp, BorderLayout.CENTER);
f.getContentPane().add(south, BorderLayout.SOUTH);
f.pack();
SwingUtilities.invokeLater(new Runnable(){
public void run() {
f.setLocationRelativeTo(null);
f.setVisible(true);
}Especially when you zoom in, you can get an unpleasant dislocation. -
ScrollBar of JScrollbar repaint continuesly ... Please help?
Hi,
I created JScrollPane in JFrame.
//Code for creating JScrollPane
compareScrollPane = new JScrollPane(this.screenCtlContainerPanel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
In it I am using JPanel control
JPanel screenCtlContainerPanel = new JPanel (new CompareLayout());
Here note this panel is created using My own custom Layour CompareLayout.
"CompareLayout implements LayoutManager."
And JPanel Contains several Comonents.
Now whenever the Scrollbar of JScrollPane is just being to visible its scrollbar are repainted continuesly...
So can anyone tell me what is wrong that is contineusly updating scrollbar effect??
I think my own custom CompareLayout is responsible for this???
Please Help
and
Thank you in advance.hi abillconsl,
Problem in Layout itself...
I am sizing all the component in this Layout ... by taking Panel;s Parent that is JViewPort.
Now as I am resizing component, Java is not being able to identify whether scrollbar is needed or not...
So once it says it is needed and another time it says not needed and scrollbar appers and disappers..
So please tell how to solve the problem... (Please don't tell to use other layout as that is not the solution)..
Code for the CompareLayout class.
//////////////////////////////////////Code for Layout.
class CompareViewLayout implements LayoutManager
//Gap.
private int leftGap,topGap,middleGap,rightGap,bottomGap;
//Set Gap.
public void setGaps(int left,int top,int middle, int right,int bottom)
this.leftGap = left;
this.topGap = top;
this.middleGap = middle;
this.rightGap = right;
this.bottomGap = bottom;
@Override
public void addLayoutComponent(String name, Component comp)
@Override
public void layoutContainer(Container parent)
<h1>//parent.getParent(), Gives JPortView and here is some problem
//So tell How to use it to not create that problem????
</h1>
Dimension max = calculateSize(parent.getParent(),parent);
//preferredLayoutSize(parent.getParent());
int compCount = parent.getComponentCount();
if ((max.width == 0) || (max.height == 0)) {
return;
int rowCount = compCount/ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN;
int colCount = 1;
if(rowCount == 0)
rowCount = 1;
if(compCount > ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
colCount = ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN;
int x = leftGap;
int y = topGap;
int row = 0;
int col = 0;
for(int count=0;count<compCount;count++)
//Here Set XY-position and Size for all the controls.
Component c = parent.getComponent(count);
c.setLocation(x, y);
c.setSize(max);
col++;
if(col >= colCount)
col = 0;
row++;
//Set here other Controls.
x = ((col * max.width) + (col * middleGap) + leftGap);
y = ((row * max.height)+ (row * middleGap) + topGap);
@Override
public Dimension minimumLayoutSize(Container parent)
componentDim.height = (2*ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_HEIGHT) + topGap + bottomGap + middleGap;
componentDim.width = (2*ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_WIDTH) + leftGap + rightGap + middleGap;
return componentDim;
@Override
public Dimension preferredLayoutSize(Container parent)
//Dimension singleScreenSize = calculateSize(parent.getParent().getParent(),parent);
Dimension singleScreenSize = calculateSize(parent.getParent(),parent);
int cnt = parent.getComponentCount();
if(cnt <= 0)
return new Dimension();
int cols = 1;
if(cnt > ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
cols = ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN;
int rows = cnt / cols + cnt%cols;
if (cnt == 0)
return new Dimension();
else
Dimension ret = new Dimension(singleScreenSize);
ret.width = cols*(ret.width) + leftGap + rightGap + (cols-1)*middleGap;
ret.height = rows*(ret.height) + topGap + bottomGap + (rows-1)*middleGap;
return ret;
@Override
public void removeLayoutComponent(Component comp)
// TODO Auto-generated method stub
* @return
private Dimension getBestFitSize(Dimension crntSize,Dimension maxsize,int nDeviceType)
//Calculate here best fit.
//This will say the best size of the component.
int minWidth = crntSize.width;
int minHeight = crntSize.height;
while(minWidth+4< maxsize.width && minHeight+3< maxsize.height)
minWidth = minWidth + 4;
minHeight = minHeight + 3;
return new Dimension(minWidth,minHeight);
private Dimension calculateSize(Container parent1,Container parent)
int componentCount = parent.getComponentCount();
Dimension parSize = parent1.getSize();
parSize.width -= 10;
parSize.height -= 10;
int scrollCount = parent1.getComponentCount();
Dimension comSize = new Dimension();
if(componentCount == ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
//Logic to get the zoom
//Only For NSpire Device.
comSize.height = ScreenCaptureConstant.SINGLE_NSPIRE_COMPONENT_HEIGHT;
comSize.width = ScreenCaptureConstant.SINGLE_NSPIRE_COMPONENT_WIDTH;
parSize.width -= (leftGap + rightGap);
if((parSize.width > comSize.width) &&
(parSize.height > comSize.height))
//Here We Get the size for the One Image.
return getBestFitSize(comSize,parSize,0);
else if(componentCount > ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
//Only Considering for NSpire Devices.
comSize.height = ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_HEIGHT + middleGap;
comSize.width = ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_WIDTH + middleGap;
//Logic to get the zoom for multiple screens.
parSize.width -= (leftGap + rightGap + middleGap);
parSize.width = parSize.width/2 ;
//Calculate Here the Size of Each Component.
if(parSize.width > comSize.width)
return new Dimension(parSize.width,getHeightFromWidth(parSize.width,0));
else
return comSize;
return comSize;
private int getHeightFromWidth(int nWidth,int nDeviceType)
int nHeight = (nWidth*3)/4;
return nHeight;
In this code As I am using JViewPort class object this is creating problem
Reasons to use JViewPort class:
1. Gives Inner Area without considering Scrollbar.
2. JScrollPane(Parent of JViewPort) is giving area with scrollbar and there is no way to identify if scrollbar is visible or not???
Becoz i have to place control in non-scroll area.
3. If I uses parent then this will alway give me Panel Size, I am not being able to get Frame/JScrollPane control Size as that is needed for the control.
Maybe you are looking for
-
Is Lightroom compatible with the Wacom Bamboo Touch Pads? I'm looking at buying one, but am hesitant if it doesn't work with Lightroom 2.0. Here's the link to their website. http://http://www.wacom.com/bamboo/bamboo_fun.php Thanks.
-
Suggestion on video converting program on Mac?
We all know QT doesn't work. Anything else? I have tried Podner which does the same as QT as in not transfering sound, and i have Handbrake which works great (though a little slow) on ripping off DVDs, but what about videos i made or clips from the i
-
Hi Guys, When i am giving loan amount in it 0045 with currency INR the error is coming "Entry INR does not exist in T500W (check entry)" although the currency has been maintained on that table Can anybody have any idea about that error regards Su
-
My 40 GB 4G iPod crapped out in less than a year. The replacement I got died in less than 4 months. All had the notorious hard drive problem that others have apparently faced. I am torn between replacing the hard drive, buying a 60 GB video iPod, or
-
Windows 2000 (SP3) crashes on K7T Pro
Hi I have a this configuration: K7T Pro (BIOS 3.6) Athlon 1200 256 Ram pc 133 Geforce 3 ti200 detonator 40.71 hdd 20gb maxtor Windows 2000 with SP3 directx 8.1 4in1 drivers the problem is windows hangs and the 4 back leds turn all green on any applic