Container context


I have been looking at a class diagram for a swing application that
refers to a container context. Can someone tell me what this refers to.

Posted On: Tuesday 23rd of October 2012 11:34:03 PM Total Views:  237
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




Displaying data in a table that lies in a container tree.

Here the structure is jPanel. jMainTabbedPanel .jRecords_Panel. jRecords_Table_Panel. jRecords_Table
VIEWS ON THIS POST

190

Posted on:

Wednesday 19th September 2012
View Replies!

real time movement for container

everybody. I am building a gui within an applet, which does have an animation and updates frequently. Therefore to prevent redrawing overlaying UI components of the animating component, i have set up a few JDialogs. These need to become relocated as the "main frame" gets moved/dragged. In order to deal with that, i have registered a componentlistener to the owner frame of the applet. Unfortunately it feels like the componentMoved event does not get called realtime. Therefore as i do move the main frame, the dialogs are moving a little bit slower, which just looks ugly. I was wondering, if there is any possibility to register/override mouseDragged of the Titilebar and extend it by my location update. It just seems that componentMoved is slightly to slow. Here is some code: @Override public void componentMoved(ComponentEvent e) { relocateDialogs(); private void relocateDialogs() { settingsParent.setLocation(getLocationOnScreen().x + getWidth() - settings.getWidth(), getLocationOnScreen().y + headerSize + offsetSettings); optionsParent.setLocation(getLocationOnScreen().x + getWidth() - options.getWidth(), getLocationOnScreen().y + headerSize + offsetOptions); legendParent.setLocation(getLocationOnScreen().x + getWidth() - legend.getWidth(), getLocationOnScreen().y + headerSize + offsetLegend); }
VIEWS ON THIS POST

117

Posted on:

Wednesday 19th September 2012
View Replies!

Modify how a container adds children

Basically, I have a grid in my display and I need to track it's children using a 3x3 array. How can I modify the container code to make it use the array instead of what it normally uses
VIEWS ON THIS POST

109

Posted on:

Monday 24th September 2012
View Replies!

real time movement for container

everybody. I am building a gui within an applet, which does have an animation and updates frequently. Therefore to prevent redrawing overlaying UI components of the animating component, i have set up a few JDialogs. These need to become relocated as the "main frame" gets moved/dragged. In order to deal with that, i have registered a componentlistener to the owner frame of the applet. Unfortunately it feels like the componentMoved event does not get called realtime. Therefore as i do move the main frame, the dialogs are moving a little bit slower, which just looks ugly. I was wondering, if there is any possibility to register/override mouseDragged of the Titilebar and extend it by my location update. It just seems that componentMoved is slightly to slow. Here is some code: @Override public void componentMoved(ComponentEvent e) { relocateDialogs(); private void relocateDialogs() { settingsParent.setLocation(getLocationOnScreen().x + getWidth() - settings.getWidth(), getLocationOnScreen().y + headerSize + offsetSettings); optionsParent.setLocation(getLocationOnScreen().x + getWidth() - options.getWidth(), getLocationOnScreen().y + headerSize + offsetOptions); legendParent.setLocation(getLocationOnScreen().x + getWidth() - legend.getWidth(), getLocationOnScreen().y + headerSize + offsetLegend); }
VIEWS ON THIS POST

111

Posted on:

Tuesday 16th October 2012
View Replies!

adding container's parent to itself error

Problem code : private void tryM (StyledDocument textPaneU, int integerF, String stringA, SimpleAttributeSet attributesJ) { //This is the method try { textPaneU.insertString(integerF, stringA, attributesJ); } catch(Exception eafff) { eafff.printStackTrace(); } } //Later...This is it being used... StyledDocument fqDOC = new DefaultStyledDocument(); SimpleAttributeSet fqPaneAttrs = new SimpleAttributeSet(); JTextPane fqPane = new JTextPane(fqDOC); fqPaneAttrs.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.green); JScrollPane fqScroll = new JScrollPane(fqPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tryM(fqDOC,0,"Test F&Q", fqPaneAttrs);
VIEWS ON THIS POST

277

Posted on:

Wednesday 17th October 2012
View Replies!

Difference between the all containers

HI Friends, I have tried to understand the difference between the containers Container, ContentPane, JPanel, RootPane, JFrame, JWindow, JApplet, etc.. But could not understand. Can I know when to use what It's my humble request to please make me understand the difference and the utilities in certain situations, when to use what.
VIEWS ON THIS POST

92

Posted on:

Wednesday 17th October 2012
View Replies!

retrieving name of container

hello . as the saying goes, i'm new so please have patience with my ignorance. i'm having a problem with a relatively simple idea. i'm creating a 10 question multiple choice quiz where a question is a class that extends JPanel and has (with the parameters in my constructor) it's own button group for answers and its own JLabel for the question. the problem i'm having is that the button to go to the next question is also part of the question class. and for me to use Card Layout (the only way i've been able to find that would work) my generic class has to know the name of the container it's stored in when calling the next method eg: void next(Container parent). is there a method i haven't found that will allow me to retrieve the name of the container so i can just leave the button in the Question class does this question even make sense here's what i have so far. public class SharkQuiz{ int numRight; String userName; public class Welcome extends JPanel{ public Welcome(){ JLabel greeting = new JLabel("Welcome. Please input your name below and click submit."); JButton submit = new JButton("Submit"); JTextField userNameField = new JTextField(15); //this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(greeting); this.add(userNameField); this.add(submit); } } public class Question extends JPanel{ public Question(String queryText, String a1Text, String a2Text, String a3Text, String a4Text, String keyText){ JPanel but = new JPanel(); JPanel answ = new JPanel(); JRadioButton a1 = new JRadioButton(a1Text); JRadioButton a2 = new JRadioButton(a2Text); JRadioButton a3 = new JRadioButton(a3Text); JRadioButton a4 = new JRadioButton(a4Text); TitledBorder ans = new TitledBorder("Answers"); final ButtonGroup answers = new ButtonGroup(); JLabel query = new JLabel(queryText); final String key = keyText; final JButton submit = new JButton("Submit"); submit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (key.equals(answers.getSelection())){ numRight++; layout.next(root); } } }); answ.setBorder(ans); answers.add(a1); answers.add(a2); answers.add(a3); answers.add(a4); answ.add(a1); answ.add(a2); answ.add(a3); answ.add(a4); but.add(submit); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(query); this.add(answ); this.add(but); } } public class Result extends JPanel{ public Result(){ JLabel message = new JLabel(""); } } public void setUpGame(){ Welcome greet = new Welcome(); Question q1 = new Question("What shark inspired the movie Jaws", "Bullshark", "Great White", "Mako", "Thresher", "Bullshark"); Result end = new Result(); JFrame base = new JFrame("Shark Quiz v1.0"); JPanel root = new JPanel(); CardLayout layout = new CardLayout(); root.setLayout(layout); //root.add(greet, "1"); root.add(q1, "2"); root.add(end, "3"); base.add(root); base.setLocationRelativeTo(null); base.setSize(400, 600); base.setVisible(true); } public static void main(String[] args){ SharkQuiz game = new SharkQuiz(); game.setUpGame(); } }
VIEWS ON THIS POST

77

Posted on:

Wednesday 17th October 2012
View Replies!

adding a window to a container

Hi all I have a table screen, and if a user right clicks on a specific row, than a pop up menu will appear, and if a user chooses an option from the pop up menu, than another screen will appear displaying information relating to the table row. This is all working fine. The screen appears and displays the relevant information. However, when the screen appears, I get an exception telling me "ADDING A WINDOW TO A CONTAINER". And, the whole application freezes. This is snippets from the code that i am using: if (source.equals(propertyItem)) { int row = tariffDescTable.getSelectedRow(); String tariffCode = tariffDescTable.getValueAt(row, 0).toString(); TariffBaseLookupProperties tblp = new TariffBaseLookupProperties(tariffCode, globalTariffBookCountry); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tblp); frame.setEnabled(true); frame.pack(); frame.setVisible(true); }
VIEWS ON THIS POST

101

Posted on:

Wednesday 17th October 2012
View Replies!

How to remove menuitem from context menu (SWT)

hi everybody can someone tell me how i can remove a menuitem from a context menu or even better how i can clear all items from a menu (like resetting the menu). i couldn't find any remove method or so. depending on the selected item i want different entries in my context menu. any ideas regards
VIEWS ON THIS POST

129

Posted on:

Thursday 18th October 2012
View Replies!

Swing: Adding components to containers

Newbie question: I'm working with a few books containing examples of Swing use...different methods are used, but basis for choice is not explained. It'd be great if someone could explain why one or the other is better: Some examples are like this, adding components directly to a JFrame: public class foo extends JFrame{ ...make some components... Container con = getContentPane(); con.setLayout(new FlowLayout()); add[components]; ... Whereas some are like this, setting a JPanel as the content pane: Some examples are like this, adding components directly to a JFrame: public class bar extends JFrame{ ...make some components... JPanel pan = new JPanel(); pan.add[components]; add(pan); ... I understand the need to change the layout from default when using the JFrame directly (at least if you want it to act like a JPanel)--it's the choice of creating the JPanel or not that I'm not clear on. Why would I use one method over the other
VIEWS ON THIS POST

89

Posted on:

Thursday 18th October 2012
View Replies!

Invoking context based WinHelp(HTML HELP) from swing.

Hi all, I am developing a swing application. I have already provided context based JavaHelp for the application and that is generated with RoboHelp. Can anybody help me in achieving the same for the winHELP(HTML HELP).
VIEWS ON THIS POST

96

Posted on:

Thursday 18th October 2012
View Replies!

Can a container have multiple layout managers?

Hi .. this question has 2 options true and false... and i have searched a lot and every time i get mixed response for this.. plzz guide me through Smyle , A container can have only one layout manager but may also contain components that each have a different layout manager. import java.awt.*; import javax.swing.*; public class Layouts { public static void main(String[] args) { JPanel top = new JPanel(), mid = new JPanel(new GridBagLayout()), low = new JPanel(new GridLayout(1,0)), center = new JPanel(new GridLayout(0,1)); top.add(new JLabel("top panel")); top.setBorder(BorderFactory.createEtchedBorder()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0,2,0,2); gbc.weightx = 1.0; addComponents(new JLabel("label 1"), new JTextField(4), mid, gbc); addComponents(new JLabel("label 2"), new JTextField(4), mid, gbc); for(int j = 0; j < 4; j++) low.add(new JButton("button " + (j + 1))); center.add(top); center.add(mid); center.add(low); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(center); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private static void addComponents(JLabel label, JTextField tf, JPanel p, GridBagConstraints gbc) { gbc.anchor = gbc.EAST; p.add(label, gbc); gbc.anchor = gbc.WEST; p.add(tf, gbc); } }
VIEWS ON THIS POST

102

Posted on:

Thursday 18th October 2012
View Replies!

Can JFrame be added to a container?

Please explain. Thank you.
VIEWS ON THIS POST

100

Posted on:

Monday 22nd October 2012
View Replies!

Problem with java layout and panels and containers

OK Guyz I'm very new to JAVA I have two programs here the one is my Case Study where you put coordinates width and height and you choose from a list of shapes and its draw it... My main problem is I cannot arrange the JButton JRadioButton and JTextField and JLabel to be in the right direction I wanted it to have two separate panels kinda like this program i grab in the net the problem is I cannot incorporate the two programs together Any help will be much appreciated my program import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CaseStudy extends JApplet { public void init() { Container content=getContentPane(); Mypanel panel=new Mypanel(); content.add(panel); resize(800,400); show(); } } class Mypanel extends JPanel implements ActionListener { JRadioButton line,circle,rectangle,triangle,pie,trapezoid,octagon; ButtonGroup group; JTextField text1,text2,text3,text4,text5,text6,text7,text8; JLabel label1,label2,label3,label4,label5,label6,label7,label8; JButton draw,showcoor; int x1=0,y1=0,x2=0,y2=0,x3=0,y3=0,x4=0,y4=0; int shapes = 0; public Mypanel() { JPanel panel1=new JPanel(); panel1.setLayout(new GridLayout(1,2)); panel1.setBackground(Color.red); JPanel panel2=new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS)); panel2.setBackground(Color.green); JPanel panel3=new JPanel(); panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS)); panel3.setBackground(Color.blue); JPanel panel4=new JPanel(); panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS)); panel4.setBackground(Color.pink); line = new JRadioButton("LINE" , true); line.addActionListener(this); circle = new JRadioButton("CIRCLE" , false); circle.addActionListener(this); rectangle = new JRadioButton("RECTANGLE" , false); rectangle.addActionListener(this); triangle = new JRadioButton("TRIANGLE" , false); triangle.addActionListener(this); pie = new JRadioButton("PIE" , false); pie.addActionListener(this); trapezoid = new JRadioButton("TRAPEZOID" , false); trapezoid .addActionListener(this); octagon = new JRadioButton("OCTAGON" , false); octagon .addActionListener(this); text1=new JTextField(4); text2=new JTextField(4); text3=new JTextField(4); text4=new JTextField(4); text5=new JTextField(4); text6=new JTextField(4); text7=new JTextField(4); text8=new JTextField(4); label1=new JLabel ("X Coor"); label2=new JLabel ("Y Coor"); label3=new JLabel ("Width"); label4=new JLabel ("Length"); label5=new JLabel ("Start Angle"); label6=new JLabel ("Arc Angle"); label7=new JLabel ("X 2 Coor"); label8=new JLabel ("Y 2 Coor"); draw=new JButton("DRAW"); showcoor=new JButton("Show Coordinates"); panel2.add(line); panel2.add(circle); panel2.add(rectangle); panel2.add(triangle); panel2.add(pie); panel2.add(trapezoid); panel2.add(octagon); panel3.add(text1); panel3.add(text2); panel3.add(text3); panel3.add(text4); panel3.add(text5); panel3.add(text6); panel3.add(text7); panel3.add(text8); panel4.add(label1); panel4.add(label2); panel4.add(label3); panel4.add(label4); panel4.add(label5); panel4.add(label6); panel4.add(label7); panel4.add(label8); panel2.add(draw); panel2.add(showcoor); draw.addActionListener(this); group=new ButtonGroup(); group.add(line); group.add(circle); group.add(rectangle); group.add(triangle); group.add(pie); group.add(trapezoid); group.add(octagon); add(panel1); add(panel2); add(panel3); add(panel4); } public void actionPerformed(ActionEvent ev) { String pindot = ev.getActionCommand(); if(pindot=="LINE"){ shapes =1; repaint(); }else if (pindot== "CIRCLE"){ shapes =2; repaint(); }else if (pindot== "RECTANGLE"){ shapes =3; repaint(); }else if (pindot== "TRIANGLE"){ shapes =4; repaint(); }else if (pindot== "PIE"){ shapes =5; repaint(); }else if (pindot== "TRAPEZOID"){ shapes =6; repaint(); }else if (pindot== "OCTAGON"){ shapes =7; repaint(); x1=Integer.parseInt(text1.getText()); x2=Integer.parseInt(text2.getText()); x3=Integer.parseInt(text3.getText()); x4=Integer.parseInt(text4.getText()); y1=Integer.parseInt(text5.getText()); y2=Integer.parseInt(text6.getText()); y3=Integer.parseInt(text7.getText()); y4=Integer.parseInt(text8.getText()); } } public void paintComponent(Graphics a) { a.setColor(new Color(162,251,160)); a.fillRect(0,0,400,400); a.setColor(Color.black); for(int i=10;i
VIEWS ON THIS POST

89

Posted on:

Monday 22nd October 2012
View Replies!

container Repaint problem

In my application i am using the same window and change the components at various button events using remove(),revalidate() and repaint(). in this code i am i have three different methods 1. initialWindow() 2. actionPerformed() in SubmitHandler class (inner class to SCJPTestApplication class) 3. actionPerformed() in BeginTest class (inner class to SCJPTestApplication class) the initialWindow () method displays the initial window which asks the user to select and submit the chapter from which he/she expects the test. On clicking the submit button on the initial window the actionPerformed method in the SubmitHandler listener class is invoked which removes the current components, revalidates, adds new components (a button called "Begin Test" and a label showing the chapter name selected for the test). DURING THE RUN THE PROGRAM WORKS PERFECTCLY TILL THIS POINT. Clicking the "Begin Test" button calls the actionPerformed() in the BeginTest class which removes the current components, adds new ones (a non-editable JTextpane holding the current question, few radiobuttons for options, and the submit button) and repaints the JPanel holding the components. The problem is that the window does not get Repainted. I have put several println() statemnts to check on the console if this actionPerformed method in the BeginTest class is executing. On the console it shows complete execution of the actionPerformed method. but the window is not repainted. I dont know why below given is the code. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package testWindow; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextPane; import javax.swing.SwingUtilities; /** * * @author hp */ public class SCJPTestApplication { private JFrame window; Container content; private JLabel qString; private JPanel question; private JButton submit; private JRadioButton op; private JList chlist; private JTextPane qPane; private String chapterSelected; private SCJPTestGenerator tg; private int qIndex; SCJPTestApplication(){ tg = new SCJPTestGenerator(); } void initialWindow(){ System.out.println("Initial Window"); window = new JFrame("SCJP 1.5 Test"); window.setBounds(100,100, 400,300); content = window.getContentPane(); String topics[]=tg.generateTopicList(); chlist = new JList(topics); submit = new JButton("Submit"); question = new JPanel(); question.add(new JLabel("Please Select the Chapter")); question.add(chlist); question.add(submit); content.add(question); submit.addActionListener(new SubmitHandler()); window.setVisible(true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } class SubmitHandler implements ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println("Submit Window"); chapterSelected = (String)chlist.getSelectedValue(); question.remove(); question.revalidate(); question.add(new JLabel(chapterSelected)); submit.setText("Begin Test"); question.add(submit); submit.addActionListener(new BeginTest()); question.repaint(); } } class BeginTest implements ActionListener{ ArrayList test ; Question q; BeginTest(){ test = tg.generateChapterTest(chapterSelected); qPane = new JTextPane(); } public void actionPerformed(ActionEvent e){ question.remove(); question.revalidate(); if(qIndex
VIEWS ON THIS POST

153

Posted on:

Monday 22nd October 2012
View Replies!

I have placed a Rectangle object in an Applet container.

I have placed a Rectangle object in an Applet container. Is there any pre-defined method to get that object when i give (x,y) point
VIEWS ON THIS POST

73

Posted on:

Monday 22nd October 2012
View Replies!

ActionListener: Non-static variable 'this' cannot be referenced from a non-static context????

Hi ! I'm not sure why the below code is giving me the error message: 'non-static variable this cannot be referenced from a non-static context', which points to tl, my TimerListener, which implements ActionListener. Is 'this' implied somewhere there that I'm not seeing I'm not sure what 'this' would have to do with my TimerListener\t I've Googled extensively and can't really find any explanation in my text. Does anyone have any ideas or an explanation If need be, I can post my other classes, but I don't think that's the issue here.
VIEWS ON THIS POST

119

Posted on:

Monday 22nd October 2012
View Replies!

can this button be align at the top left coner of a container

import java.awt.event.*; import java.awt.*; import javax.swing.event.*; import javax.swing.*; public class HomePage extends JFrame { JFrame frame; public HomePage() { frame = new JFrame("Home"); frame.setBounds(100, 100,600,500); setGUIPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setGUIPanel() { Container content = frame.getContentPane(); content.setLayout(new BorderLayout(10,10)); //create a Base panel to hold navigation and display panels JPanel basePanel = new JPanel(); basePanel.setLayout(new GridLayout(0,2,5,5)); content.add("Center",basePanel); //create left panel and it's components and //add to the Base panel JPanel navPanel = new JPanel(); //Dimension size = new Dimension(80,20); Box controlBox = Box.createVerticalBox(); JButton main = new JButton("Main"); //main.setPreferredSize(size); JButton employ = new JButton("Employee"); //employ.setPreferredSize(size); JButton admin = new JButton("Admin"); //admin.setPreferredSize(size); //add button to the BoxLayout controlBox.add(main); controlBox.add(employ); controlBox.add(admin); //add controlBox to navPanel navPanel.add(controlBox); //add navPanel to BasePanel basePanel.add(navPanel); frame.setVisible(true); } public static void main(String[] args) { HomePage hp = new HomePage(); } }
VIEWS ON THIS POST

95

Posted on:

Monday 22nd October 2012
View Replies!

LayoutManagers and containers

Hi people, I'm kind of new when it comes to designing a GUI. I find it REAL hard to actually place components where i'd like them. Is the use of LayoutManagers and various containers common in normal Swing GUI For example, would i divide the JFrame up into four containers (JPanels): ____ |_||_| |_||_| (one JFrame, 4 JPanels) and then each panel can get a diferrent LayoutManager implementation Would this be normal (I can only use the Java Swing API and no other 3rd party project because it's for my SCJD). And what i don't understand is why the components fill up all of the cells. Can someone please help me with this design problem i am having
VIEWS ON THIS POST

66

Posted on:

Tuesday 23rd October 2012
View Replies!