Swing/AWT/SWT :: Aspect Ratio Of Components
Aug 18, 2011Any good way to keep a certain aspect ratio of a Component, when the Container is resized?
View RepliesAny good way to keep a certain aspect ratio of a Component, when the Container is resized?
View RepliesI'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 View RelatedI have a JPanel with vertical BoxLayout. It contains four components. I set the JPanel to LEFT_ALIGNMENT, which has no effect on its components. I set the first component to LEFT_ALIGNMENT, which has no effect. Only after I have set all four components to LEFT_ALIGNMENT do any of them align properly.
This suggests that it is impossible to have varying alignments in a container. They must all be the same alignment.
I accept that this is just the way things are: "Java works in mysterious ways." And I'm sure that it is possible to work around this limitation by stacking boxes that themselves have different internal alignments.
But I still wonder what in the world was going on in the minds of the Java developers. Is there a rational reason for this oddity?
This raises my most serious criticism of Swing: the hidden gotcha. Swing is a tangled mess of cross-connecting requirements that are impossible to divine by simple inspection of the documentation. If you want to use, say, a JRadioButton, it's not enough to study the documentation on JRadioButtons; you must also consult lots of documents for which there is no obvious connection to JRadioButton other than it being part of Swing.
I am trying to send a JPanel object to the server. While doing so I get the error -
java.io.NotSerializableException: javax.swing.filechooser.WindowsFileSystemView
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
[code]....
How to fix this error?
I have swing UI designed and I want the components to resize when the frame is manually resized. The design is as shown in the fig Project UI.jpg
The panel 4 and panel 5 will change their contents according to the list item clicked. Panel 4 just has text area but panel 5 a panel with numerous components as label, combo box, text field,check box will be present.Now if the frame resizes, I won't all the components to resize according to the frame size.
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?
I keep hearing these two term when it comes to painting in Swing, however, I'm not sure which is which. To my understanding is that the child components are the ones that already exist on screen (could be a JButton, JFrame, or custom painting) . and the parent components are the one to be added/drawn next. (hence, if we override the paintChildren() method when painting, the components that were already on the screen don't appear any more).
View Replies View RelatedI 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:
My panel named panelIncomeInfo are not showing the components that I have added.
public class PayrollGUI {
private JPanel panelIncomeInfo = new JPanel ();
private JPanel panel = new JPanel ();
private JPanel panelPayCheckInfo = new JPanel ();
private JButton close = new JButton ("Close");
[Code] .....
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]....
I keep hearing these two term when it comes to painting in Swing, however, I'm not sure which is which. To my understanding is that the child components are the ones that already exist on screen (could be a JButton, JFrame, or custom painting) . and the parent components are the one to be added/drawn next. (hence, if we override the paintChildren() method when painting, the components that were already on the screen don't appear any more) ....
View Replies View RelatedI wish to display a progress bar during a lengthy file translation process. When I created a ProgressBar class to do this and tested it with a short test program, it seemed to work fine. But when I add my ProgressBar class to a package containing various other classes, put that package in a jar file, and then execute the class using the progress bar from a menu in my main program, the frame of the progress bar shows up with the appropriate caption but the JLabel, JProgressBar, and JButton are not displayed. I have gone over my code numerous times and checked that the ProgressBar class constructor is getting the proper arguments.
// package gov.nasa.jpl.ephemeris;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Progress bar with message text above the bar and a Cancel button below it
*/
public class ProgressBar extends JFrame {
private boolean _cancelled = false;
private JProgressBar _progressBar = null;
[Code] ....
I have also been wondering whether I need a separate instance of the border for each panel, or whether I can just create one instance and use it for all three panels.
I'm working on Ubuntu with resolution 1600*900; I used MigLayout to place the components of the application; but when I go with higher resolutions,components adjustment and alignment are not up to the mark.
View Replies View RelatedI have quite a specific view for how I want my components layed out. No matter what I try I can get them to display how I want! I'm using three JPanels. There's a main panel that goes inside the tabbed pane. This main panel contains two other panels. The First panel is a gridbaglayout panel, with labels on the left column, and components on the right column. The second panel is underneath the second, and contains a label, and a button beneath it. THis uses a basic box layout, with one component per line. The label doesn't always appear (depends if a component is changed). With everything showing, this is how it looks so far:
However, I want the Labels on the left of the pane. The right hand column should be aligned horizontally and have more space from the labels. Ideally I'd like a gap between the last label/checkbox and the Note label.
This is my current code for the panel/s inside the tabbed pane window.
videoPanel = new JPanel();
applyVidBtn = new JButton("Apply Settings");
applyVidBtn.setVisible(false);
warningLbl = new JLabel("Note. Applying these settings causes a program restart.");
warningLbl.setVisible(false);
[Code] .....
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]....
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
I decide to make a new GUI just for fun and practise and i want to learn more about Layouts.. right know i am try to understand some staff about GridBagLayout.
I want to make a GUI with this Layout :
So..first i am a frame with borderlayout then i put a JMenuBar and bla bla bla and i create panel with GridLayout which i put on myFrame.add(panel1,BorderLayout.WEST) and also i make an another JPanel which i put of the Center of main Frame (myFrame.add(panel2,BorderLayout.Center))
when i run the program i get this GUI :
Now the problem is that i can't put the JButton on the top of the gridLayout just to look like the first picture.. i Read about anchor and i try to
gbc.anchor = GridBagConstraints.NORTH; but without results.. still the components are on the middle of the JPanel..
Here is my Code () :
Java Code:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
[Code] .....
I know my problem is my lack of understanding of OOP but I have searched for a solution and can't even seem to get close.This is a very simplified version of what I will need to do. I have a button and six textboxes. When the button is pressed I want to take the text from textbox6 and place it in textbox1, textbox2, textbox3, textbox4, and textbox5.
I need sometthing better then this brut force method.Java Code:
package textboxes;
public class TextBoxesGUI extends javax.swing.JFrame {
public String NewText;
public TextBoxesGUI() {
initComponents();
[code]....
Really need some simple and complete example on how to extends components (graphically and functionally) for primefaces 5.
For example I can't figure how to add custom attributes to existing component or define default values for existing attributes.
Is there any tutorial or a basic common way to achieve this goal or each component have to be extended in its way?
In some examples I see jsf components inside the tag view, other times dont.
- Is it important to put all jsf components inside "the view" tag?
- What would be the difference not putting them inside this tag?
I want to make a simple Table Tennis game. I have 2 drawing classes. 1st should draw oval and 2nd rectangle. But second class, which should draw rectangle doesn't work and if i use it together with oval class, then oval doesn't appear too.
Java Code:
public static void main(String[] args) throws InterruptedException
{
Intro i = new Intro();
Pall pall = new Pall();
Laud laud = new Laud();
i.frameID().add(pall); // this adds oval
i.frameID().add(laud); // this adds rectangle
i.frameID().pack();
i.frameID().setSize(400, 400);
[code]...
Currently I get errors when trying to exit my JFrame without playing the youtube video I have set it to load.
My Code:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
[Code] ....
If it's relevant the error:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
[Code] .....
As I couldn't find a way to do the printing of multiple items on one page, I decided to test out my idea. I found that I could have a table in a JTextPane.
However, whenever I got to print, my table will vanish. It doesn't even need to go to the printer. Just bringing up the print dialog will make it vanish like tax money in D.C.
(Also, I'm not really that familiar with JTextPane and it seems harder than JTextArea. Which part is controlling the font of my regular text by the way? I think it might be tableParagraph but it could also be the base font. I can try and fiddle with both and waste paper but where the font is being set.
Setting the font with setFont() will vanish my table. )
Somehow, I'm thinking that the solution might be JTextPane.setContentType() or setEditorKit() or both. (I"m not that familiar with either, but I fear that it's only being set to handle text, hence any graphics are being lost.)
Here is my code:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.text.*;
public class AddingTables {
JTextPane textPane;
private Object[][] rows;
private Object[] colNames;
[Code] ....
dynamically create tabs by pressing a button, each tab has Primefaces input texts in which i'll be adding stuff and with a Submit button i'm submitting the form.
My issue now is this; although I can create more buttons through my managed bean, I cannot set the ValueExpression to the InputTexts. When I do:
inputName.setValueExpression("value", createValueExpression("#{cdiBean.name}",String.class)); it doesn't work.
The createValueExpression is a static method in my managed bean and it returns a ValueExpression. I'm most certain I found it online, not sure where though, it's been over a month since the last time I worked with this topic.
Anyway, is my whole "methodology" correct? Should I do anything differently?
I'm trying to get my components to align in the proper position but I'm having no luck what so ever. I have my code and I've attached an image of my window builder. It's just one of those small aggravating things thats probably right under my Noes.
Here's my code
package tsd.view;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
[Code] .....
Attached image(s)
If we have request which hit the server, before it reaches servlet or the response going to send the browsers, through how many components it pass through (or the process flow).
View Replies View Related