Swing/AWT/SWT :: How To Create A JPanel That Maintains Same Aspect Ratio When Resized
Feb 23, 2014
I'm trying to create a chess program that uses a JPanel with an 8 by 8 grid layout with 64 jlabels with icons. However, I don't want the icons to be distorted if the user resizes the window in such a way that makes the panel not square. Is there any way I could create a JPanel that maintains a square aspect ratio when it is resized?
View Replies
ADVERTISEMENT
Aug 18, 2011
Any good way to keep a certain aspect ratio of a Component, when the Container is resized?
View Replies
View Related
May 6, 2014
Is there a way to create insets for the JPanel without using the GridBagLayout, or createEmptyBorder() because the panel already wants to have an etched border?
View Replies
View Related
Jun 1, 2014
So I am making a JPanel with two JLabels and it isn't working right.
import java.awt.*;
import javax.swing.*;
public class IntroPanel extends JPanel
{
public IntroPanel() {
setBackground(Color.green);
[Code] ....
For some reason
JLabel 11 = new JLabel("Layout Manger Demonstration");
JLabel 12 = new JLabel ("Choose a tab to see an example of a layout manger.");
add(11);
add(12);
is not registering the JLabel or add functions.
View Replies
View Related
Apr 17, 2014
I have coded to create jPanel as image and save to desktop but the image is saved only in my src folder in My Documents. Here is my code-
public static BufferedImage getScreenShot(Component component){
BufferedImage image= new BufferedImage(component.getWidth(),component.getHeight(),BufferedImage.TYPE_INT_RGB);
component.paint(image.getGraphics());
[Code] ....
View Replies
View Related
Sep 27, 2014
How do i add a ratio into this program. it needs to find the ratio from lowercase to uppercase.
import java.util.Scanner;
public class Strings
{
public static void main(String[] args)
[Code]....
View Replies
View Related
Dec 20, 2014
I am trying to make movingLabel move to a different JPanel each time the JButton is clicked. I can see that the random integer is changing each time the button is clicked, but the movingLabel wasn't doing anything. I noticed that if I click the button and then resize the JFrame with my mouse, it shows in the correct panel. Is there something I am missing, or is there a way to make it automatically display in the correct panel without having to manually resize the JFrame each time? I was thinking that I could add something that resizes the window slightly each time the button is clicked to show it, but I don't think that is probably the "right" way to do it.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class JMovingFrame extends JFrame implements ActionListener
[code]...
View Replies
View Related
Nov 10, 2013
What is the ratio of Memory(RAM) to heap space ? ie: When JVM will throw OutOfMemoryError based on heap available to JVM ?
OutofMemoryError - Memory:RAM size
View Replies
View Related
Apr 17, 2014
Pretty much the title. Everything was running fine until a moment, when pain updated only once after the first resize. I've seen some worries about th.start(); or repaint(); but I did not manage to track the problem down since I'm a rookie at programming. Here's the Main class.
import java.applet.*;
import java.awt.*;
public class Main extends Applet implements Runnable
{
// variables
Thread th;
Player player;
static Shot [] shots;
[Code] ....
View Replies
View Related
Jan 18, 2015
This is an old project that I had working probably 2 years ago. Since I reopened it the only thing I have changed is the database location. This is a very basic project I did to dip my toes in to Java. I'm going to add it to my portfolio but just to clarify I am not a Java developer so this is mainly there to show that I am not completely blind when it comes to Java.
//Import libraries
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
import java.sql.DriverManager;
[Code]...
Errors when I click the button that launches the JFrame:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
[Code]...
It will launch the window but it will be blank. If I resize the window it will show me the headers. If I click below the headers were the data should be, it will show me the data.
Since it has been so long the only thing I can think of is some of the code has become antiquated. As I said, this was working originally. I just fired it up again to take some screenshots for my portfolio.
View Replies
View Related
Oct 3, 2014
I would like to know the possible ways to put up JInternalFrame over JPanel to achieve the following output.
Is it even Possible because i learned JInternalFrame can only be added to JDesktopPane.?
View Replies
View Related
Feb 19, 2014
Trying to get an image to display in a GUI.
try {
ByteArrayInputStream in = new ByteArrayInputStream(
transferWorker.bOutput
.toByteArray());
BufferedImage bufferedImage = ImageIO
.read(in);
[Code] ....
But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed. Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.
View Replies
View Related
Apr 9, 2014
I have a Jframe and i want to add inside 4 different jpanel.This is easy.
what is difficult is how can i change them dynamically with 4 other new jpanels and 4 other new jpanels?
I have try with BorderLayout but not working.
It's a wizard like but not the same.
I have a jpanel with jbuttons jpanel with a jtable jpanel with textarea and jpanel with jlabels. All this have to change with other 4 jpanels, where to look?
View Replies
View Related
Nov 7, 2014
How can I make a call to paintComponent within the JPanel-class, from another Class?
In class TestClass:
public class TestClass {
public TestClass() {
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(500,500);
initComponents();
[Code] .....
View Replies
View Related
Dec 28, 2014
I have been trying to create a chat client which makes use of a scrollable jpanel and at runtime adds JTextFields to the panel.
Panel Initialising
msgPanel = new JPanel(new MigLayout());
msgPanel.setPreferredSize(new Dimension(400,335));
JScrollPane msgPanelScroll = new JScrollPane(msgPanel);
msgPanelScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
msgPanelScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
mainPanel.add(msgPanelScroll,"span 3,alignx center,wrap");
[Code] .....
But now Im facing the following issues. The text field aligns to the center of the panel & on adding more fields the panel accommodates as it can and does not begin scrolling.
Screenshots attatched
View Replies
View Related
Apr 4, 2014
I pick this code from Head first Java
package GUI;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
public class gui5 {
int x=0;
int y=0;
public static void main(String... x) {
[code]...
but just a Jframe is appearing no Jpanel no green color circle?What is wrong with code
View Replies
View Related
Mar 27, 2014
I am try to do an application based in multiples JFrames, each one with its particular responsibilities, and use one JPanel as a menu with buttons that connect one JFrame to another, But this menu is instantiated at run in view (layout made by netbeans) the Main Jframe appears with its internal JPanel, but the instantiated JPanel does not appear or does not show it's buttons. (notice only run method in the second class):
JPanel Menu that will be used in all alone JFrames of application:
public class MenuSuperior extends javax.swing.JPanel {
public MenuSuperior() {
initComponents();
} private void initComponents() {
[Code] .....
View Replies
View Related
Oct 8, 2001
Let me explain by simplifying the GUI to a simple frame in which I have a JCheckbox and a JPanel mypanel.mypanel has a Textfield tf,JComboBox cmb as it's components.So now if I deselect the JCheckbox, all the components in the mypanel should be disabled. I used a code like:
[code]mycheckbox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(mycheckbox.isSelected())
mypanel.setEnabled(true); else
mypanel.setEnabled(false); } });[code]
but the components inside the panels are not disabled. In my actual program I have a large number of different kinds of components in mypanel.So disabling/enabling each of them on each actionPerformed of the mycheckbox will be laborious. Isn't there any way by which I can disable/enable the mypanel to disable/enable all the components in it?
View Replies
View Related
Apr 4, 2014
I trying to replace original (and empty) JPanel in JFrame with my own made one, components does no appear right, when I pass the mouse first button appears:
MainViewClass:
...
private void initComponents() {
...
MenujPanel = new MenuSuperior();
MenujPanel.setBorder(
BorderFactory.createTitledBorder("Dados Pessoais"));
[Code] .....
Here is the video:
View Replies
View Related
Apr 12, 2015
I need to add 2 JLists inside a JPanel for a crossword. The JPanel is located SOUTH and I'm using BorderLayout in the constructor to locate the JPanel.
The problem is, I can't see the 2 JLists inside the JPanel. For some strange reason the JLists appear in the center where the crosswordPanel is, even though the clues JPanel method is located SOUTH.
package crossword;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
[code]....
View Replies
View Related
Jul 3, 2014
I am trying to add buttons in a loop to my but when i compile my program i can`t see my buttons. I can see other stuff that added to jpanel ...
static JButton blocks[][];
for (int i = 0; i < block.length; i++) {
for (int j = 0; j < block[i].length; j++) {
block[i][j] = new Block(i, j);
blocks[i][j] = new JButton(i+"");
blocks[i][j].setLayout(new GridLayout((i+1) * 10, (i+1) * 10, 10, 10));
pageAxisPanel.add(blocks[i][j]);
}
}
View Replies
View Related
Jun 4, 2014
I have used the following code and I am trying to render a String in the JPanel. The text is getting displayed in the mirror image format.
I understand that there is a problem with .scale(), not able to get an idea about the corrective step. Please run the below class.
class Surface extends JPanel {
final int PAD = 40;
private void doDrawing(Graphics g)
{
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
[Code] ....
View Replies
View Related
Oct 23, 2014
I'd like to enable/disable a jpanel and it's entire contents in one fell swoop. I could of course call each component's .setEnabled() method, but I figured there must be a better way!
View Replies
View Related
Jan 29, 2015
I have created a JFrame that contains 3 JPanel.
My problem is, when i clicked in the bouton to expand the Frame,the 3 JPanel are fixed and do not expanded with the Jframe.
View Replies
View Related
Jan 10, 2014
My JPanel when adding components to it will never make its self larger but it will make my components inside smaller even though I have set the minimum and preferred sizes for those components? I am using the GridBagLayout for my layout manager as I am trying to get used to it.
package manning;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
[code]....
View Replies
View Related
Apr 7, 2015
I want to delete the shape i have drawn on the panel. Here is my code
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
[Code] ....
Why it is not deleting my rectangle.
View Replies
View Related