Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8267705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:37:44+00:00 2026-06-08T05:37:44+00:00

I have this method to print and set the material properties of a Solid

  • 0

I have this method to print and set the material properties of a Solid Object in a class called MaterialProperties, which has printMaterial & setMaterial methods.

public void Btn3_callback ( ) throws Exception {
        Model model = session.GetCurrentModel();

        if (model == null) {
            mesg = "No Model Selected!!";
            //TextField.Area("No Model Selected!!");
            System.exit(0);
        }
        else {
            Solid solid= (Solid) model;
            String newMaterial="copper";//user input for new Material name
            printMaterial(solid);//printMaterial print the Material properties of the Solid object
            setMaterial(solid,newMaterial);//setMaterial sets the Material properties of the Solid object to the material entered
        }
    }

I need to get the user input for newMaterial instead of hard coding it. What I need to do is to display all the Material types avaialable, so that the user can just select the material required. So I tried to do this using JFrame. Here’s the code I have:

public class MaterialWindow {

    JFrame frame = new JFrame("Material Selection");
     public MaterialWindow(){
             // Directory path here
      String path = "W:\\materials"; 

      JFrame frame = new JFrame("Material Selection");
      JPanel panel = new JPanel(new GridLayout(0, 4));
      ButtonGroup bg = new ButtonGroup();

      String files;
      File folder = new File(path);
      File[] listOfFiles = folder.listFiles(); 
      JRadioButton  button;

      for (int i = 0; i < listOfFiles.length; i++) 
      {

       if (listOfFiles[i].isFile()) 
       {
       files = listOfFiles[i].getName();
           if (files.endsWith(".mtl") || files.endsWith(".MTL"))
           {

              button = new JRadioButton(files);
              panel.add(first,BorderLayout.CENTER);
              panel.revalidate(); 

              bg.add(button);

              first.addActionListener(new MyAction());


            }
         }
      }

 frame.add(panel, BorderLayout.NORTH);
 frame.getContentPane().add(new JScrollPane(panel), BorderLayout.CENTER);
 frame.setSize(1000, 400);
 frame.setVisible(true);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }



public class MyAction implements ActionListener{

    public void actionPerformed(ActionEvent e){

        String newMaterial =e.getActionCommand();
        String[] split = newMaterial.split("\\.");
        newMaterial = split[0];
        newMaterial.trim();
              //set the newMaterial for btn3_callback OR call the setMaterial method of MaterialPropeties class
        frame.dispose();
    }

}


}

Now the problem is how can I use the newMaterial string selected from the radio button to newMaterial in my Btn3_callback() function? When I create a getString() method for newMaterial in the class MyAction and use that it Btn3_callback it always returns null;

Is there any way I can do this? Or any different way I can implement the idea?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:37:45+00:00Added an answer on June 8, 2026 at 5:37 am

    Use a JOptionPane instead of the frame. Put a list (JList ..or JComboBox) of options in the option pane and query the component once returned (the pane is closed), for the selected object.

    E.G. using JComboBox

    The GUI should be created and altered on the EDT (batteries not included).

    import java.io.File;
    import javax.swing.*;
    
    public class QuickTest {
    
        public static void main(String[] args) throws Exception {
            File[] files = new File(System.getProperty("user.home")).listFiles();
            JFrame f = new JFrame("Faux J-Link");
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            JEditorPane jep = new JEditorPane();
            f.add(new JScrollPane(jep));        
            f.setSize(600,400);
            f.setLocationByPlatform(true);
            f.setVisible(true);
    
            JComboBox choices = new JComboBox(files);
            int result = JOptionPane.showConfirmDialog(f, choices);
            if (result==JOptionPane.OK_OPTION) {
                System.out.println("OK");
                File file = files[choices.getSelectedIndex()];
                jep.setPage(file.toURI().toURL());
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method which lets me translate the position of an object, animating
I have this method which leaks ~ 6KB : + (EInspectorFacilityInfo*) newWithNode: (CXMLNode*) node
I have this method that gets called when i press a button and removes
I have this method in cs page: public String getToolTip(Object productId, Object imgBtnId) {
I have a Model in an existing Datastore. Which looks like this: class SomeKind(db.Model):
I have a class method which returns the result in multidimension. the method i
I am New to Spring.I have this question which has been bothering me for
I've got a Tile class with this method: public object Clone() { return MemberwiseClone();
I have this method to display the contact numbers in my inbox: public ArrayList<String>
I have this method (someone else wrote it!) - (CGPDFDocumentRef)getPdf { NSArray *paths =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.